/** * Remove an element from the right digit. * * @param pos position inside the right digit * @return resulting tree */ private FingerTree<N, E> removeRight(final long pos) { if (right.length > 1) { // right digit cannot underflow, just delete the element return new DeepTree<>(left, leftSize, middle, remove(right, pos), size - 1); } // singleton digit might underflow final Node<N, E> node = right[0]; if (!middle.isEmpty()) { // potentially balance with middle tree final InnerNode<N, E> last = (InnerNode<N, E>) middle.last(); final Node<N, E> lastSub = last.getSub(last.arity() - 1); final NodeLike<N, E>[] rem = node.remove(lastSub, null, pos); final Node<N, E> newLastSub = (Node<N, E>) rem[0], newNode = (Node<N, E>) rem[1]; if (newNode == null) { // nodes were merged final Node<N, E>[] newRight = last.children.clone(); newRight[newRight.length - 1] = newLastSub; return new DeepTree<>(left, leftSize, middle.init(), newRight, size - 1); } @SuppressWarnings("unchecked") final Node<N, E>[] newRight = new Node[] {newNode}; // replace last node in middle tree final Node<Node<N, E>, E> newLast = last.replaceLast(newLastSub); return new DeepTree<>(left, leftSize, middle.replaceLast(newLast), newRight, size - 1); } // balance with left digit final Node<N, E> lastLeft = left[left.length - 1]; final NodeLike<N, E>[] rem = node.remove(lastLeft, null, pos); final Node<N, E> newLastLeft = (Node<N, E>) rem[0], newNode = (Node<N, E>) rem[1]; if (newNode == null) { // nodes were merged if (left.length == 1) { // only one node left return new SingletonTree<>(newLastLeft); } @SuppressWarnings("unchecked") final Node<N, E>[] newRight = new Node[] {newLastLeft}; return get(slice(left, 0, left.length - 1), newRight, size - 1); } @SuppressWarnings("unchecked") final Node<N, E>[] newRight = new Node[] {newNode}; if (newLastLeft == lastLeft) { // deletion could be absorbed return get(left, leftSize, newRight, size - 1); } // adapt the left digit final Node<N, E>[] newLeft = left.clone(); newLeft[newLeft.length - 1] = newLastLeft; return get(newLeft, newRight, size - 1); }
private boolean removeNode(String path) { Resource templateResource = resourceResolver.getResource(path); if (templateResource != null) { Node nodeToDelete = templateResource.adaptTo(Node.class); if (nodeToDelete != null) { try { nodeToDelete.remove(); TemplateUtils.saveNode(nodeToDelete); session.save(); return true; } catch (VersionException ex) { java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName()) .log(Level.SEVERE, null, ex); } catch (LockException ex) { java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName()) .log(Level.SEVERE, null, ex); } catch (ConstraintViolationException ex) { java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName()) .log(Level.SEVERE, null, ex); } catch (AccessDeniedException ex) { java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName()) .log(Level.SEVERE, null, ex); } catch (RepositoryException ex) { java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName()) .log(Level.SEVERE, null, ex); } finally { session.logout(); } } } return false; }
public T remove(T value) { if (root == null || !root.contains(value)) { return null; } else { return root.remove(value); } }
/** test query and get methods on a node withouth keys */ public void testEmptyNode() { Node n = new Node(); assertTrue(n.getKeys().size() == 0); assertTrue(!n.hasKeys()); assertTrue(!n.hasKey("nosuchkey")); assertTrue(n.keySet().isEmpty()); n.remove("nosuchkey"); // should work }
protected Node<K, V> removeRight(K key, Context<K, V> ctx, boolean force) { Node<K, V> newRight = right.remove(key, ctx, force); if (newRight.isInternal()) { this.right = newRight; return this; } else { return ctx.nf.mkShortBoth(bit(), leftKey, leftVal, newRight.getKey(), newRight.getValue()); } }
protected Node<K, V> removeLeft(K key, Context<K, V> ctx, boolean force) { Node<K, V> newLeft = left.remove(key, ctx, force); if (newLeft.isInternal()) { this.left = newLeft; return this; } else { return ctx.nf.mkShortLeft(bit(), newLeft.getKey(), newLeft.getValue(), right); } }
public <E extends Entry<K, V>> E remove(K key) { if (key == null) { return updateNullEntry(null); } @SuppressWarnings("unchecked") E removedEntry = (E) root.remove(conf, key); if (removedEntry != null) { afterRemoveProcessing(); } return removedEntry; }
/** Remove tags from a node with two tags and test the state of the node. */ public void testRemove() { Node n = new Node(); n.put("key.1", "value.1"); n.put("key.2", "value.2"); n.remove("nosuchkey"); // should work assertTrue(n.getKeys().size() == 2); // still 2 tags ? n.remove("key.1"); assertTrue(n.getKeys().size() == 1); assertTrue(!n.hasKey("key.1")); assertTrue(n.get("key.1") == null); assertTrue(n.hasKey("key.2")); assertTrue(n.get("key.2").equals("value.2")); n.remove("key.2"); assertTrue(n.getKeys().size() == 0); assertTrue(!n.hasKey("key.1")); assertTrue(n.get("key.1") == null); assertTrue(!n.hasKey("key.2")); assertTrue(n.get("key.2") == null); }
private T remove(T value) { T hold = value; Node L = this; if (left != null && left.equals(value)) { hold = left.data; shift(left); // L = L.left; // left = null; } else if (right != null && right.equals(value)) { hold = right.data; shift(right); right = null; } else { if (left != null) { left.remove(value); } if (right != null) { right.remove(value); } } return hold; }
@SuppressWarnings("unchecked") public V remove(Object key) { Object o = root.remove(comparator, key); if (null != o) { size--; if (root.hasOnlyChild()) { root = (Node) root.firstValue(); } } return (V) o; }
// merge multiple <head> or <body> contents into one, delete the remainder, and ensure they are // owned by <html> private void normaliseStructure(String tag, Element htmlEl) { Elements elements = this.getElementsByTag(tag); Element master = elements.first(); // will always be available as created above if not existent if (elements.size() > 1) { // dupes, move contents to master List<Node> toMove = new ArrayList<Node>(); for (int i = 1; i < elements.size(); i++) { Node dupe = elements.get(i); for (Node node : dupe.childNodes) toMove.add(node); dupe.remove(); } for (Node dupe : toMove) master.appendChild(dupe); } // ensure parented by <html> if (!master.parent().equals(htmlEl)) { htmlEl.appendChild(master); // includes remove() } }
@Override public Object remove(Comparator comparator, Object key) { int index = findKeyIndex(comparator, key); int nodeOffset = index * 2; Node node = (Node) getChild(nodeOffset); Object oldVal = node.remove(comparator, key); if (node.requiresCompacting()) { if (node instanceof Leaf) { compactLeaves((Leaf) node, index, nodeOffset); } else { compactBranches((Branch) node, index, nodeOffset); } } return oldVal; }
private void normaliseStructure(String tag, Element htmlEl) { Elements elements = getElementsByTag(tag); Element master = elements.first(); if (elements.size() > 1) { List<Node> toMove = new ArrayList(); for (int i = 1; i < elements.size(); i++) { Node dupe = elements.get(i); for (Node node : dupe.childNodes) { toMove.add(node); } dupe.remove(); } for (Node dupe : toMove) { master.appendChild(dupe); } } if (!master.parent().equals(htmlEl)) { htmlEl.appendChild(master); } }
/** * Wait for signal with no spurious wakeup. Exclusive latch must be held, which is still held when * method returns. * * @param node newly allocated node * @param nanosTimeout relative nanosecond time to wait; infinite if <0 * @param nanosEnd absolute nanosecond time to wait until; used only with >0 timeout * @return -1 if interrupted, 0 if timed out, 1 if signaled */ int await(Latch latch, Node node, long nanosTimeout, long nanosEnd) { node.mWaiter = Thread.currentThread(); Node tail = mTail; if (tail == null) { mHead = node; } else { tail.mNext = node; node.mPrev = tail; } mTail = node; if (nanosTimeout < 0) { while (true) { latch.releaseExclusive(); LockSupport.park(); latch.acquireExclusive(); int state = node.resumed(this); if (state != 0) { return state; } } } else { while (true) { latch.releaseExclusive(); LockSupport.parkNanos(nanosTimeout); latch.acquireExclusive(); int state = node.resumed(this); if (state != 0) { return state; } if (nanosTimeout == 0 || (nanosTimeout = nanosEnd - System.nanoTime()) <= 0) { node.remove(this); return 0; } } } }
/** * Checks whether the node is inside a field or should be skipped and then removes it if * necessary. */ private void CheckDepthAndRemoveNode(Node node) { if (mFieldDepth > 0 && !mNodesToSkip.contains(node)) node.remove(); }
/** * Remove an element from the left digit. * * @param pos position inside the left digit * @return resulting tree */ private FingerTree<N, E> removeLeft(final long pos) { if (left.length > 1) { // left digit cannot underflow, just delete the element return new DeepTree<>(remove(left, pos), leftSize - 1, middle, right, size - 1); } // singleton digit might underflow final Node<N, E> node = left[0]; if (!middle.isEmpty()) { // next node for balancing is in middle tree final InnerNode<N, E> head = (InnerNode<N, E>) middle.head(); final Node<N, E> first = head.getSub(0); final NodeLike<N, E>[] rem = node.remove(null, first, pos); final Node<N, E> newNode = (Node<N, E>) rem[1], newFirst = (Node<N, E>) rem[2]; if (newNode == null) { // nodes were merged final Node<N, E>[] newLeft = head.children.clone(); newLeft[0] = newFirst; return get(newLeft, middle.tail(), right, size - 1); } @SuppressWarnings("unchecked") final Node<N, E>[] newLeft = new Node[] {newNode}; if (newFirst != first) { // nodes were balanced final FingerTree<Node<N, E>, E> newMid = middle.replaceHead(head.replaceFirst(newFirst)); return new DeepTree<>(newLeft, newNode.size(), newMid, right, size - 1); } // no changes to this tree's structure return new DeepTree<>(newLeft, newNode.size(), middle, right, size - 1); } // potentially balance with right digit final NodeLike<N, E>[] rem = node.remove(null, right[0], pos); final Node<N, E> newNode = (Node<N, E>) rem[1], newFirstRight = (Node<N, E>) rem[2]; if (newNode == null) { // nodes were merged if (right.length == 1) return new SingletonTree<>(newFirstRight); final int mid = right.length / 2; final Node<N, E>[] newLeft = slice(right, 0, mid); newLeft[0] = newFirstRight; return get(newLeft, middle, slice(right, mid, right.length), size - 1); } // structure does not change @SuppressWarnings("unchecked") final Node<N, E>[] newLeft = new Node[] {newNode}; if (newFirstRight == right[0]) { // right digit stays the same return new DeepTree<>(newLeft, newLeft[0].size(), middle, right, size - 1); } // adapt the right digit final Node<N, E>[] newRight = right.clone(); newRight[0] = newFirstRight; return new DeepTree<>(newLeft, newNode.size(), middle, newRight, size - 1); }
public V remove(Object k) { if (root == null) { return null; } final K key = AbstractCritBitTree.<K>cast(k); if (!root.isInternal()) { if (ctx().chk.bitIndex(key, root.getKey()) < 0) { V out = root.getValue(); root = null; size--; return out; } else { return null; } } Node<K, V> grandparent = null; Node<K, V> parent = null; Node<K, V> cur = root; for (; ; ) { switch (cur.next(key, ctx())) { case LEFT: if (cur.hasExternalLeft()) { Node<K, V> leftNode = cur.left(ctx()); if (ctx().chk.bitIndex(key, leftNode.getKey()) < 0) { if (grandparent == null) { root = root.remove(key, ctx(), true); } else { grandparent.remove(key, ctx(), true); } size--; return leftNode.getValue(); } else { return null; } } grandparent = parent; parent = cur; cur = cur.left(ctx()); break; case RIGHT: if (cur.hasExternalRight()) { Node<K, V> rightNode = cur.right(ctx()); if (ctx().chk.bitIndex(key, rightNode.getKey()) < 0) { if (grandparent == null) { root = root.remove(key, ctx(), true); } else { grandparent.remove(key, ctx(), true); } size--; return rightNode.getValue(); } else { return null; } } grandparent = parent; parent = cur; cur = cur.right(ctx()); break; } } }
public T remove(T value) { if (root == null) { throw new NoSuchElementException(); } return root.remove(value); }