ifclass LineCompCompressor static LCLongerProds lcSimplifyToLongerProductions(LineCompCompressor comp) { ret lcSimplifyToLongerProductions( map(countIterator_exclusive(0, comp.nLiterals()), i -> comp.itemToString(i)), map(countIterator_exclusive(comp.nLiterals(), comp.nItems()), i -> comp.getPair(i)), comp.finalEncodings); } endif static LCLongerProds lcSimplifyToLongerProductions(LS literals, L pairs, Map> files) { new LCLongerProds lc; lc.literals = literals; int nLiterals = l(literals); for i over pairs: lc.productions.put(nLiterals+i, intPairToList(pairs.get(i))); lc.files = mapValues cloneList(files); bool change; do { ping(); change = false; new MultiSet counts; for (L l : concatLists(values(lc.productions), values(lc.files))) for (int i : l) if (i >= nLiterals) counts.add(i); for (int i : cloneList(counts.asSet())) if (counts.get(i) == 1) { set change; L unrolled = assertNotNull(lc.productions.get(i)); print("Unrolling " + i + " => " + unrolled); lc.productions.remove(i); counts.remove(i); for (L l : concatLists(values(lc.productions), values(lc.files))) replaceSublist(l, ll(i), unrolled); } } while (change); ret lc; }