/** * Restore P2 at node and upward the spine. Note that P2 can vanish * at some nodes sideways as a result of this. We'll fix that later * in compressFully when needed. */ private void compressUpward(long node) { double threshold = Math.floor(size / compressionFactor); long atNode = get(node); while (!isRoot(node)) { if (atNode > threshold) { break; } long atSibling = get(sibling(node)); if (atNode + atSibling > threshold) { break; } long atParent = get(parent(node)); if (atNode + atSibling + atParent > threshold) { break; } node2count.addTo(parent(node), atNode + atSibling); node2count.remove(node); if (atSibling > 0) { node2count.remove(sibling(node)); } node = parent(node); atNode = atParent + atNode + atSibling; } }
/** * Restore P2 at seedNode and guarantee that no new violations of P2 appeared. */ private void compressDownward(long seedNode) { double threshold = Math.floor(size / compressionFactor); // P2 check same as above but shorter and slower (and invoked rarely) LongArrayFIFOQueue q = new LongArrayFIFOQueue(); q.enqueue(seedNode); while (!q.isEmpty()) { long node = q.dequeueLong(); long atNode = get(node); long atSibling = get(sibling(node)); if (atNode == 0 && atSibling == 0) { continue; } long atParent = get(parent(node)); if (atParent + atNode + atSibling > threshold) { continue; } node2count.addTo(parent(node), atNode + atSibling); node2count.remove(node); node2count.remove(sibling(node)); // Now P2 could have vanished at the node's and sibling's subtrees since they decreased. if (!isLeaf(node)) { q.enqueue(leftChild(node)); q.enqueue(leftChild(sibling(node))); } } }
@Override public boolean remove(long k) { final int oldSize = size; Long2LongOpenHashMap.this.remove(k); return size != oldSize; } @Override
public void remove() { if (last == -1) throw new IllegalStateException(); if (last == n) { containsNullKey = false; } else if (pos >= 0) shiftKeys(last); else { // We're removing wrapped entries. Long2LongOpenHashMap.this.remove(wrapped.getLong(-pos - 1)); last = -1; // Note that we must not decrement size return; } size--; last = -1; // You can no longer remove this entry. if (ASSERTS) checkTable(); } public int skip(final int n) {
/** * Restore P2 at node and upward the spine. Note that P2 can vanish * at some nodes sideways as a result of this. We'll fix that later * in compressFully when needed. */ private void compressUpward(long node) { double threshold = Math.floor(size / compressionFactor); long atNode = get(node); while (!isRoot(node)) { if (atNode > threshold) { break; } long atSibling = get(sibling(node)); if (atNode + atSibling > threshold) { break; } long atParent = get(parent(node)); if (atNode + atSibling + atParent > threshold) { break; } node2count.addTo(parent(node), atNode + atSibling); node2count.remove(node); if (atSibling > 0) { node2count.remove(sibling(node)); } node = parent(node); atNode = atParent + atNode + atSibling; } }
/** * Restore P2 at seedNode and guarantee that no new violations of P2 appeared. */ private void compressDownward(long seedNode) { double threshold = Math.floor(size / compressionFactor); // P2 check same as above but shorter and slower (and invoked rarely) LongArrayFIFOQueue q = new LongArrayFIFOQueue(); q.enqueue(seedNode); while (!q.isEmpty()) { long node = q.dequeueLong(); long atNode = get(node); long atSibling = get(sibling(node)); if (atNode == 0 && atSibling == 0) { continue; } long atParent = get(parent(node)); if (atParent + atNode + atSibling > threshold) { continue; } node2count.addTo(parent(node), atNode + atSibling); node2count.remove(node); node2count.remove(sibling(node)); // Now P2 could have vanished at the node's and sibling's subtrees since they decreased. if (!isLeaf(node)) { q.enqueue(leftChild(node)); q.enqueue(leftChild(sibling(node))); } } }