Warning: session_start(): open(/var/lib/php/sessions/sess_qt92jk88s19h04crm0e1poo2qe, 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
sclass LineComp_PairIndex {
bool verbose;
MultiSetMap nodes = multiSetMap_innerHashSet_outerHashMap();
MultiSetMap byCount = multiSetMap_innerTreeSet_outerRevTreeMap();
Map chains;
// a "chain" of nodes (one input file)
class Ch {
Node tail;
*(L l) {
fOr (int i : l) add(i);
}
L toList() {
new L l;
Node node = tail;
while (node != null) {
l.add(node.value);
node = node.prev;
}
ret reverseInPlace(l);
}
void add(int i) {
new Node n;
n.ch = this;
n.value = i;
n.prev = tail;
if (tail != null) tail.next = n;
tail = n;
add(n);
}
}
class Node {
Ch ch;
int value;
Node prev, next;
int a() { ret value; }
int b() { ret next == null ? -1 : next.value; }
IntPair pair() { ret next == null ? null : IntPair(a(), b()); }
}
IntPair nodeToPair(Node n) {
ret n?.pair();
}
// add node to pair index
void add(Node n) {
IntPair p = nodeToPair(n);
if (p == null) ret;
int count = nodes.getSize(p);
nodes.add(p, n);
byCount.remove(count, p);
byCount.put(count+1, p);
}
// remove node from pair index
void remove(Node n) {
IntPair p = nodeToPair(n);
if (p == null) ret;
int count = nodes.getSize(p);
if (count == 0) fail("Can't remove pair " + p);
nodes.remove(p, n);
byCount.remove(count, p);
if (count-- > 0) byCount.put(count, p);
}
IntPair mostPopularDuplicate() {
ret toInt(firstKey(byCount)) < 2 ? null : firstValue(byCount);
}
int numberOfDuplicates() {
ret byCount.size()-l(byCount.get(1));
}
int getCount(IntPair p) {
ret nodes.getSize(p);
}
void replacePair(int pa, int pb, int replaceWith) {
IntPair p = IntPair(pa, pb);
Set set = nodes.get(p);
for (Node n : cloneList(set)) {
continue if n.a() != pa || n.b() != pb; // nodes might have been deleted or changed
replacePair(n, replaceWith);
}
}
void replacePair(Node node, int replaceWith) {
remove(node.prev);
remove(node);
remove(node.next);
node.value = replaceWith;
deleteNode(node.next);
add(node.prev);
add(node);
}
void deleteNode(Node node) {
if (node.next != null) node.next.prev = node.prev; else node.ch.tail = node.prev;
if (node.prev != null) node.prev.next = node.next;
node.value = -1; // mark invalid
}
}