public void removeCursor(String name) { long stamp = rwLock.writeLock(); try { Item item = cursors.remove(name); // Move the item to the right end of the heap to be removed Item lastItem = heap.get(heap.size() - 1); swap(item, lastItem); heap.remove(item.idx); // Update the heap siftDown(lastItem); } finally { rwLock.unlockWrite(stamp); } }
/** * Push the item up towards the the root of the tree (lowest reading position). */ private void siftUp(Item item) { Item parent = getParent(item); while (item.idx > 0 && parent.position.compareTo(item.position) > 0) { swap(item, parent); parent = getParent(item); } }
/** * Push the item down towards the bottom of the tree (highest reading position). */ private void siftDown(final Item item) { while (true) { Item j = null; Item right = getRight(item); if (right != null && right.position.compareTo(item.position) < 0) { Item left = getLeft(item); if (left != null && left.position.compareTo(right.position) < 0) { j = left; } else { j = right; } } else { Item left = getLeft(item); if (left != null && left.position.compareTo(item.position) < 0) { j = left; } } if (j != null) { swap(item, j); } else { break; } } }
public void removeCursor(String name) { long stamp = rwLock.writeLock(); try { Item item = cursors.remove(name); // Move the item to the right end of the heap to be removed Item lastItem = heap.get(heap.size() - 1); swap(item, lastItem); heap.remove(item.idx); // Update the heap siftDown(lastItem); } finally { rwLock.unlockWrite(stamp); } }
public void removeCursor(String name) { long stamp = rwLock.writeLock(); try { Item item = cursors.remove(name); // Move the item to the right end of the heap to be removed Item lastItem = heap.get(heap.size() - 1); swap(item, lastItem); heap.remove(item.idx); // Update the heap siftDown(lastItem); } finally { rwLock.unlockWrite(stamp); } }
/** * Push the item up towards the the root of the tree (lowest reading position). */ private void siftUp(Item item) { Item parent = getParent(item); while (item.idx > 0 && parent.position.compareTo(item.position) > 0) { swap(item, parent); parent = getParent(item); } }
/** * Push the item up towards the the root of the tree (lowest reading position) */ private void siftUp(Item item) { Item parent = getParent(item); while (item.idx > 0 && parent.position.compareTo(item.position) > 0) { swap(item, parent); parent = getParent(item); } }
/** * Push the item down towards the bottom of the tree (highest reading position) */ private void siftDown(final Item item) { while (true) { Item j = null; Item right = getRight(item); if (right != null && right.position.compareTo(item.position) < 0) { Item left = getLeft(item); if (left != null && left.position.compareTo(right.position) < 0) { j = left; } else { j = right; } } else { Item left = getLeft(item); if (left != null && left.position.compareTo(item.position) < 0) { j = left; } } if (j != null) { swap(item, j); } else { break; } } }
/** * Push the item down towards the bottom of the tree (highest reading position). */ private void siftDown(final Item item) { while (true) { Item j = null; Item right = getRight(item); if (right != null && right.position.compareTo(item.position) < 0) { Item left = getLeft(item); if (left != null && left.position.compareTo(right.position) < 0) { j = left; } else { j = right; } } else { Item left = getLeft(item); if (left != null && left.position.compareTo(item.position) < 0) { j = left; } } if (j != null) { swap(item, j); } else { break; } } }