+ this.labels = labels;
+ }
+ public void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target) {
+ gather(tl, ht, target, new Tree[ht.length], 0);
+ }
+ private void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target, Tree[] trees, int i) {
+ if (i==ht.length) {
+ target.add(new Tree<T>(null, tag, trees));
+ return;
+ }
+ for(Tree<T> tree : ht[i]) {
+ if (unwrap && i==trees.length-1) {
+ // I think this is wrong
+ Tree[] trees2 = new Tree[trees.length - 1 + tree.numChildren()];
+ System.arraycopy(trees, 0, trees2, 0, trees.length-1);
+ for(int j=0; j<tree.numChildren(); j++)
+ trees2[trees.length-1+j] = tree.child(j);
+ target.add(new Tree<T>(null, tag, trees2));
+ } else {
+ trees[i] = tree;
+ gather(tl, ht, target, trees, i+1);
+ trees[i] = null;
+ }
+ }
+ }
+ public void expand(TaskList tl, HashSet<Tree<T>> ht) {
+ if (singleton) {
+ tokens[0].expand(tl, ht);
+ return;
+ }
+ HashSet<Tree<T>>[] children = new HashSet[tokens.length];
+ tl.gather(this, children, ht);
+ for(int i=0; i<children.length; i++) {
+ children[i] = new HashSet<Tree<T>>();
+ tl.expand(tokens[i], children[i]);
+ }