static L lineComp_replaceSublistWithUpdatingPairCount(L l, L x, L y, LineComp_PairCounts pairCounts) { if (x == null) ret l; int i = 0; while (true) { i = indexOfSubList(l, x, i); if (i < 0) break; int to = i+l(x), to_new = i+l(y); ifdef lineComp_replaceSublistWithUpdatingPairCount_debug print("Replacing " + subList(l, i, to) + " at " + i); endifdef pairCounts.removeAll(overlappingIntPairs(subList(l, i-1, to+1))); replaceSublist(l, i, to, y); pairCounts.addAll(overlappingIntPairs(subList(l, i-1, to_new+1))); i = to_new; } ret l; }