Warning: session_start(): open(/var/lib/php/sessions/sess_46eo879i2nvu8aql7d4pt5t9s7, 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
cprint {
transient LineCompedSingle lc;
transient LL productions;
transient Map prodLengths; // prod index -> length of production in characters
transient int iFirstPair, iFirstFile;
transient Map literalIndex;
transient MultiMap prodIndex; // keys: item looked for, value: pair(prod index, position in prod)
start-thread {
new LineCompCompressor comp;
lc = lcString2(comp, "hello world world");
// Turn pairs and file encodings into a single structure ("productions")
productions = new L;
productions.addAll(rep(null, l(lc.literals)));
iFirstPair = l(productions);
productions.addAll(intPairsToLists(lc.pairs));
iFirstFile = l(productions);
productions.add(lc.main);
calcProdLengths();
// build the reconstitution index
literalIndex = indexList(lc.literals);
prodIndex = new MultiMap;
for iProd over productions: {
L prod = productions.get(iProd);
for (int i, int x : unpair iterateListWithIndex(prod)) {
prodIndex.put(x, intPair(iProd, i));
}
}
print(+literalIndex);
print(+prodIndex);
S query = "world";
L queryList = characters(query);
new L queryLiterals;
for (Char c : queryList) {
Int iLit = literalIndex.get(c);
if (iLit == null) ret with print("literal not found");
queryLiterals.add(iLit);
}
print(+queryLiterals);
reconstitute(queryLiterals, 0);
}
void calcProdLengths {
prodLengths = new Map;
for (int i = iFirstPair; i < l(productions); i++)
getProdLength(i);
}
int getProdLength(int i) {
if (i < iFirstPair) ret 1; // literal
Int x = prodLengths.get(i);
if (x != null) ret x;
prodLengths.put(i, x = intSum(lmap getProdLength(productions.get(i))));
ret x;
}
void reconstitute(L baseList, int i) {
L needLeft = subList(baseList, 0, i);
L needRight = subList(baseList, i+1);
print("Reconstituing " + quote(lcUncompressItem(lc, baseList.get(i)));
print(" needLeft: " + quote(lcUncompressItems(lc, needLeft)));
print(" needRight: " + quote(lcUncompressItems(lc, needRight)));
L l = prodIndex.get(baseList.get(i));
print("Found: " + l);
for (IntPair p : l) {
L prod = productions.get(p.a);
int j = p.b;
bool isFile = p.a >= iFirstFile;
if (isFile)
print("Reached file level");
else {
if (j == 0) {
print("checking right: " + quote(lcUncompressItem(lc, prod.get(1)))
+ " => " + itemStartsWith(prod.get(1), needRight));
} else
print("should checkleft");
}
}
}
bool itemStartsWith(int i, L need) {
/*if (empty(need)) true;
if (i == first(need)) true;
L prod = productions.get(i);
if (prod == null) false;
itemStartsWith(prod.first(*/
ret startsWith(lcUncompressItems(lc, need), lcUncompressItem(lc, i));
}
}