Warning: session_start(): open(/var/lib/php/sessions/sess_7rsetlt85pknleo3f1ed2i1n2l, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
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;
}
}
static Tokenization makeTokenization(L tokens) {
new Tokenization tok;
for (S t : tokens) {
LinkedToken lt = new(t);
lt.t = t;
if (tok.first == null)
tok.first = lt;
else {
lt.prev = tok.last;
tok.last.next = lt;
}
tok.last = lt;
lt.prevIdentical = tok.lastByContent.get(t);
if (lt.prevIdentical == null)
tok.firstByContent.put(t, lt);
else {
lt.prevIdentical.nextIdentical = lt;
}
tok.lastByContent.put(t, lt);
}
ret tok;
}
p-experiment {
S text = "hello hello";
L tokens = javaTok(text);
Tokenization tok = makeTokenization(tokens);
printStruct(tok);
assertVerbose(true);
assertEquals(true, tok.contains("hello"));
assertEquals(true, tok.contains(" "));
assertEquals(false, tok.contains("x"));
assertEquals(2, tok.countInstances("hello"));
assertEquals(1, tok.countInstances(" "));
assertEquals(0, tok.countInstances("x"));
print("OK!");
}