sclass LazyValueTreeMap extends TreeMap {
static O placeholder = new O; // fool type system
O valueMaker;
*(Collection keys, O *valueMaker) {
for (A key : unnull(keys)) put(key, (B) placeholder);
}
public B get(O key) {
B value = super.get(key);
if (value == placeholder)
put((A) key, value = (B) callF(valueMaker, key));
ret value;
}
int numPlaceholders() {
ret countOccurrences_id(values(), placeholder);
}
// revert to identity hashcode
public bool equals(O o) { ret this == o; }
public int hashCode() { ret systemHashCode(this); }
}