import java.lang.reflect.*;
/** an efficient representation of a collection of trees (Tomita's shared packed parse forest) */
-public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ implements Visitable<Forest.Body<T>> {
+public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ implements Visitable<Forest.Body<T>>, IntegerMappable {
+
+ private static int master_idx = 0;
+ private final int idx = master_idx++;
+ public int toInt() { return idx; }
/** assume that this forest contains exactly one tree and return it; otherwise throw an exception */
public final Tree<T> expand1() throws Ambiguous, ParseFailed {
static class Ref<T> extends Forest<T> {
private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
public Ref() { }
+ public int toInt() {
+ if (hp.size()==1) return hp.iterator().next().toInt();
+ return super.toInt();
+ }
public void merge(Forest p) { if (p!=this) hp.add(p, true); }
public <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
if (hp==null) return;