public void PairRecycle(Pair pair) { //TODO: CHECK IF WORKS // Share the pool of the master tree. // TODO: would be lovely to move the pairs stuff into an external data structure. var tree = GetMasterTree(); pair.a.prev = tree.pooledPairs; tree.pooledPairs = pair; }
public Pair MakePair(Node leafA, Pair nextA, Node leafB, Pair nextB) { var pair = this.pooledPairs; if (pair != null) { this.pooledPairs = pair.a.prev; pair.a.prev = null; pair.a.leaf = leafA; pair.a.next = nextA; pair.b.prev = null; pair.b.leaf = leafB; pair.b.next = nextB; return pair; } else { cp.numPairs++; return new Pair(leafA, nextA, leafB, nextB); } }
public Thread(Pair prev, Node leaf, Pair next) { this.prev = prev; this.leaf = leaf; this.next = next; }
public static void Unlink(Pair prev, Node leaf, Pair next) { if (next != null) { if (next.a.leaf == leaf) next.a.prev = prev; else next.b.prev = prev; } if (prev != null) { if (prev.a.leaf == leaf) prev.a.next = next; else prev.b.next = next; } else { leaf.pairs = next; } }
// Objects created with constructors are faster than object literals. :( public Pair(Node leafA, Pair nextA, Node leafB, Pair nextB) { a = new Thread(null, leafA, nextA); b = new Thread(null, leafB, nextB); id = 0; }