sclass LinkedToken { S t; LinkedToken prev, next; LinkedToken prevIdentical, nextIdentical; *() {} *(S *t) {} } sclass Tokenization { LinkedToken first, last; new Map firstByContent; new Map lastByContent; bool contains(S t) { ret firstByContent.get(t) != null; } int countInstances(S t) { int n = 0; LinkedToken lt = firstByContent.get(t); while (lt != null) { ++n; lt = lt.nextIdentical; } ret n; } }