sclass UniqueList extends RandomAccessAbstractList {
new L list;
new Map index; // position of each element
public A get(int i) { ret list.get(i); }
public int size() { ret list.size(); }
// couldn't come up with a better name here... add element or
// get its index if it's already there
int addOrGetIndex(A a) {
Int i = index.get(a);
if (i == null) {
index.put(a, i = size());
list.add(a);
}
ret i;
}
public bool add(A a) {
int n = size();
ret addOrGetIndex(a) == n;
}
}