projects
/
sbp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
checkpoint
[sbp.git]
/
src
/
edu
/
berkeley
/
sbp
/
Forest.java
diff --git
a/src/edu/berkeley/sbp/Forest.java
b/src/edu/berkeley/sbp/Forest.java
index
65a8095
..
0fb10c6
100644
(file)
--- a/
src/edu/berkeley/sbp/Forest.java
+++ b/
src/edu/berkeley/sbp/Forest.java
@@
-119,7
+119,7
@@
public abstract class Forest<T> implements GraphViz.ToGraphViz {
// Many //////////////////////////////////////////////////////////////////////////////
/** An "ambiguity node"; this is immutable once it has been "looked at" */
// Many //////////////////////////////////////////////////////////////////////////////
/** An "ambiguity node"; this is immutable once it has been "looked at" */
- public static class Many<T> extends Forest<T> {
+ public static class Many<T> extends Forest<T> implements Iterable<One<T>> {
HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
@@
-127,6
+127,11
@@
public abstract class Forest<T> implements GraphViz.ToGraphViz {
public Many() { }
public Many() { }
+ public Iterator<One<T>> iterator() {
+ touched();
+ return (Iterator<One<T>>)(Object)hp.iterator(); // FIXME: fastset's iterator is not safe!
+ }
+
public Tree<T> expand1() throws Ambiguous {
touched();
if (hp.size() > 1) {
public Tree<T> expand1() throws Ambiguous {
touched();
if (hp.size() > 1) {
@@
-153,7
+158,14
@@
public abstract class Forest<T> implements GraphViz.ToGraphViz {
}
private void touched() {
}
private void touched() {
+ if (touched) return;
touched = true;
touched = true;
+ FastSet<Forest<T>> f2 = new FastSet<Forest<T>>();
+ for(Forest f : hp)
+ if (f instanceof Forest.One) f2.add(f);
+ else for(Forest ff : ((Forest.Many<T>)f))
+ f2.add(ff);
+ hp = f2;
}
public boolean contains(Forest f) {
touched();
}
public boolean contains(Forest f) {
touched();