Clean up the Tree by DFS traversal.

Remove the node that has no children and no notifications associated
with them.
@param node
769954
private void cleanUpHistoryTree(HistoryNode node) {
    if (node == null || node.children == null) {
      return;
    }
    
    Iterator<HistoryNode> iterator = node.children.iterator();
    while (iterator.hasNext()) {
      HistoryNode child = iterator.next();
      
      // clean up child
      cleanUpHistoryTree(child);
      
      // clean up current node;
      if (shouldRemoveNode(child)) {
        iterator.remove();
      }
    }
  }
515162
public boolean removeChild(Node node) throws ChildNodeException {
    Node currNode = getFirstChild();
    boolean rc = false;

    if (!allowChildren) {
      throw new ChildNodeException();
    }

    if (node != null && !isLeaf()) {
      // Is this the first and only child
      if (node == currNode && node == currNode.getNextSibling()) {
        setFirstChild(null);
        rc = true;
      } else {
        // Verify that this Node is a child here
        do {
          if (currNode == node) {
            // Remove this child
            if (node.getPrevSibling() != null) {
              node.getPrevSibling().setNextSibling(node.getNextSibling());
            }
            if (node == getFirstChild()) {
              setFirstChild(node.getNextSibling());
            }

            rc = true;

            // do not release. Item.resolve expects the 
            // pointers to be intact after a remove
            //node.release();
            break;
          }
          currNode = currNode.getNextSibling();
        } while (currNode != getFirstChild());
      }
    }

    return rc;
  }
1029982
protected void removeSiblings(final NodeData node)
   {
      if (node.getIdentifier().equals(Constants.ROOT_UUID))
      {
         return;
      }

      // remove child nodes of the item parent recursive
      writeLock.lock();
      try
      {
         // remove on-parent child nodes list
         nodesCache.remove(node.getParentIdentifier());

         // go through the C and remove every descendant of the node parent
         final QPath path = node.getQPath().makeParentPath();
         final List<CacheId> toRemove = new ArrayList<CacheId>();

         // find and remove by path
         for (Iterator<Map.Entry<CacheKey, CacheValue>> citer = cache.entrySet().iterator(); citer.hasNext();)
         {
            Map.Entry<CacheKey, CacheValue> ce = citer.next();
            CacheKey key = ce.getKey();
            CacheValue v = ce.getValue();
            if (v != null)
            {
               if (key.isDescendantOf(path))
               {
                  // will remove by id too
                  toRemove.add(new CacheId(v.getItem().getIdentifier()));

                  citer.remove(); // remove

                  nodesCache.remove(v.getItem().getIdentifier());
                  propertiesCache.remove(v.getItem().getIdentifier());
               }
            }
            else
            {
               citer.remove(); // remove empty C record
            }
         }

         for (CacheId id : toRemove)
         {
            cache.remove(id);
         }

         toRemove.clear();

      }
      finally
      {
         writeLock.unlock();
      }
   }
70480
def _remove_node(self, node):
        

        self.graph.remove_node(node)
        if node.addr in self._nodes:
            del self._nodes[node.addr]

        # We wanna remove the function as well
        if node.addr in self.kb.functions:
            del self.kb.functions[node.addr]

        if node.addr in self.kb.functions.callgraph:
            self.kb.functions.callgraph.remove_node(node.addr)
1001294
public boolean removeAfter(Node node) {

        if (node == null || node.next == null) {
            return false;
        }

        if (node.next == last) {
            last = node;
        }

        node.next = node.next.next;

        return true;
    }
1145305
public static void removeChild(Node parent, Node node) {
    if (isTryFinallyNode(parent, node)) {
      if (NodeUtil.hasCatchHandler(getCatchBlock(parent))) {
        // A finally can only be removed if there is a catch.
        parent.removeChild(node);
      } else {
        // Otherwise, only its children can be removed.
        node.detachChildren();
      }
    } else if (node.isCatch()) {
      // The CATCH can can only be removed if there is a finally clause.
      Node tryNode = node.getGrandparent();
      checkState(NodeUtil.hasFinally(tryNode));
      node.detach();
    } else if (isTryCatchNodeContainer(node)) {
      // The container node itself can't be removed, but the contained CATCH
      // can if there is a 'finally' clause
      Node tryNode = node.getParent();
      checkState(NodeUtil.hasFinally(tryNode));
      node.detachChildren();
    } else if (node.isBlock()) {
      // Simply empty the block.  This maintains source location and
      // "synthetic"-ness.
      node.detachChildren();
    } else if (isStatementBlock(parent)
        || isSwitchCase(node)
        || node.isMemberFunctionDef()) {
      // A statement in a block or a member function can simply be removed
      parent.removeChild(node);
    } else if (isNameDeclaration(parent) || parent.isExprResult()) {
      if (parent.hasMoreThanOneChild()) {
        parent.removeChild(node);
      } else {
        // Remove the node from the parent, so it can be reused.
        parent.removeChild(node);
        // This would leave an empty VAR, remove the VAR itself.
        removeChild(parent.getParent(), parent);
      }
    } else if (parent.isLabel()
        && node == parent.getLastChild()) {
      // Remove the node from the parent, so it can be reused.
      parent.removeChild(node);
      // A LABEL without children can not be referred to, remove it.
      removeChild(parent.getParent(), parent);
    } else if (parent.isVanillaFor()) {
      // Only Token.FOR can have an Token.EMPTY other control structure
      // need something for the condition. Others need to be replaced
      // or the structure removed.
      parent.replaceChild(node, IR.empty());
    } else if (parent.isObjectPattern()) {
      // Remove the name from the object pattern
      parent.removeChild(node);
    } else if (parent.isArrayPattern()) {
      if (node == parent.getLastChild()) {
        parent.removeChild(node);
      } else {
        parent.replaceChild(node, IR.empty());
      }
    } else if (parent.isDestructuringLhs()) {
      // Destructuring is empty so we should remove the node
      parent.removeChild(node);
      if (parent.getParent().hasChildren()) {
        // removing the destructuring could leave an empty variable declaration node, so we would
        // want to remove it from the AST
        removeChild(parent.getParent(), parent);
      }
    } else if (parent.isRest()) {
      // Rest params can only ever have one child node
      parent.detach();
    } else if (parent.isParamList()) {
      parent.removeChild(node);
    } else if (parent.isImport()) {
      // An import node must always have three child nodes. Only the first can be safely removed.
      if (node == parent.getFirstChild()) {
        parent.replaceChild(node, IR.empty());
      } else {
        throw new IllegalStateException("Invalid attempt to remove: " + node + " from " + parent);
      }
    } else {
      throw new IllegalStateException("Invalid attempt to remove node: " + node + " of " + parent);
    }
  }
1119984
public void removeSubtree( Tree<T> subtree )
    {
        if ( children.remove( subtree ) )
        {
            subtree.parent = null;
        }
    }
1318275
public void remove(T node) {
		for (int i = 0; i < numberOfReplicas; i++) {
			circle.remove(hashFunc.hash(node.toString() + i));
		}
	}
1279969
function (node) {

        var toberemoved = this.handler[node];
        this.handler[node] = [];

        // remove handler
        if (toberemoved && toberemoved.length > 0) {
            for (var i = 0, l = toberemoved.length; i < l; i++) {
                this._connection.deleteHandler(toberemoved[i])
            }
        }
    }
835990
public function removeNode(\Ydle\HubBundle\Entity\Node $node)
    {
        $this->nodes->removeElement($node);
    }
969713
private void trimNode(final Node node) {
        NodeList children = node.getChildNodes();
        for (int i = children.getLength() - 1; i >= 0; i--) {
            trimChild(node, children.item(i));
        }
    }
952052
public function removeNode(Node $node)
    {
        $node->setNavigation(null);
        $this->nodes->removeElement($node);
    }
542357
def remove_node(self, node):
        

        if node in self._nodes:
            yield from node.delete()
            self._nodes.remove(node)
304176
public void remove(int node) {
        if (node == NIL) {
            throw new IllegalArgumentException();
        }
        if (left(node) != NIL && right(node) != NIL) {
            // inner node
            final int next = next(node);
            assert next != NIL;
            swap(node, next);
        }
        assert left(node) == NIL || right(node) == NIL;

        final int parent = parent(node);
        int child = left(node);
        if (child == NIL) {
            child = right(node);
        }

        if (child == NIL) {
            // no children
            if (node == root) {
                assert size() == 1 : size();
                root = NIL;
            } else {
                if (node == left(parent)) {
                    left(parent, NIL);
                } else {
                    assert node == right(parent);
                    right(parent, NIL);
                }
            }
        } else {
            // one single child
            if (node == root) {
                assert size() == 2;
                root = child;
            } else if (node == left(parent)) {
                left(parent, child);
            } else {
                assert node == right(parent);
                right(parent, child);
            }
            parent(child, parent);
        }

        release(node);
        rebalance(parent);
    }
937776
function removeNode(node){
    
    // Remove incoming edges.
    Object.keys(edges).forEach(function (u){
      edges[u].forEach(function (v){
        if(v === node){
          removeEdge(u, v);
        }
      });
    });

    // Remove outgoing edges (and signal that the node no longer exists).
    delete edges[node];

    return graph;
  }
813582
public boolean remove(Tree<T> node) {
    return getChild(node)
        .map(function(n -> n.parent = null))
        .map(children::remove)
        .orElse(false);
  }
1280153
@Override
  public void removeChildren(Element node) {

    NodeList children = node.getChildNodes();
    for (int i = (children.getLength() - 1); i >= 0; i--) {
      node.removeChild(children.item(i));
    }
  }