Remove nodes higher in the tree that occur further down the
        SAME branch. If they occur down OTHER branchs leave them alone.

        NOTE: modifies in place!
433683
def dematerialize(parent_name, parent_node):  # FIXME we need to demat more than just leaves!
    #FIXME still an issue: Fornix, Striatum, Diagonal Band
    
    lleaves = {}
    children = parent_node[parent_name]

    if not children:  # children could be empty ? i think this only happens @ root?
        #print('at bottom', parent_name)
        lleaves[parent_name] = None
        return lleaves

    children_ord = reversed(sorted(sorted(((k, v)
                                           for k, v in children.items()),
                                          key=alphasortkey),
                                          #key=lambda a: f'{a[0]}'.split('>')[1] if '>' in f'{a[0]}' else f'a[0]'),
                                          #key=lambda a: a[0].split('>') if '>' in a[0] else a[0]),
                                   key=tcsort))  # make sure we hit deepest first

    for child_name, _ in children_ord:  # get list so we can go ahead and pop
        #print(child_name)
        new_lleaves = dematerialize(child_name, children)
        if child_name == 'magnetic resonance imaging':  # debugging failing demat
            pass
            #embed()

        if child_name in new_lleaves or all(l in lleaves for l in new_lleaves):
            # if it is a leaf or all childs are leaves as well
            if child_name in lleaves:  # if it has previously been identified as a leaf!
                #print('MATERIALIZATION DETECTED! LOWER PARENT:',
                      #lleaves[child_name],'ZAPPING!:', child_name,
                      #'OF PARENT:', parent_name)
                children.pop(child_name)
                #print('cn', child_name, 'pn', parent_name, 'BOTTOM')
            #else:  # if it has NOT previously been identified as a leaf, add the parent!
                #new_lleaves[child_name] = parent_name  # pass it back up to nodes above
                #print('cn', child_name, 'pn', parent_name)
        #else:  # it is a node but we want to dematerizlize them too!
        lleaves[child_name] = parent_name

        lleaves.update(new_lleaves)

    return lleaves
1012367
function removeTreeRoot(heap, root, prev) {
  // Remove root from the heap
  if (root === heap.head) {
    heap.head = root.sibling;
  } else {
    prev.sibling = root.sibling;
  }

  // Reverse the order of root's children and make a new heap
  var newHead;
  var child = root.child;
  while (child) {
    var next = child.sibling;
    child.sibling = newHead;
    child.parent = undefined;
    newHead = child;
    child = next;
  }
  var newHeap = new BinomialHeap();
  newHeap.head = newHead;

  heap.union(newHeap);
}
725917
public void clear() {
        // Clearing all of the links between nodes is "unnecessary", but:
        // - helps a generational GC if the discarded nodes inhabit
        //   more than one generation
        // - is sure to free memory even if there is a reachable Iterator
        for (Node<E> x = first; x != null; ) {
            Node<E> next = x.next;
            x.item = null;
            x.next = null;
            x.prev = null;
            x = next;
        }
        first = last = null;
        size = 0;
        modCount++;
    }
1091268
protected Node removeNode( Node node )
    {
        // Remove node.
        node.previous.next = node.next;
        node.next.previous = node.previous;
        node.removed = true;
        return node;
    }
1000350
def _clear(self, node, left, right):
        
        if self.lazyset[node] is not None:  # first do the pending set
            val = self.lazyset[node]
            self.minval[node] = val
            self.maxval[node] = val
            self.sumval[node] = val * (right - left)
            self.lazyset[node] = None
            if left < right - 1:            # not a leaf
                self.lazyset[2 * node] = val    # propagate to direct descendents
                self.lazyadd[2 * node] = 0
                self.lazyset[2 * node + 1] = val
                self.lazyadd[2 * node + 1] = 0
        if self.lazyadd[node] != 0:        # then do the pending add
            val = self.lazyadd[node]
            self.minval[node] += val
            self.maxval[node] += val
            self.sumval[node] += val * (right - left)
            self.lazyadd[node] = 0
            if left < right - 1:            # not at a leaf
                self.lazyadd[2 * node] += val     # propagate to direct descendents
                self.lazyadd[2 * node + 1] += val
838416
def delete_nodes(self, nodes: Iterable[str]):
        
        for n in nodes:
            if self.has_node(n):
                self.remove_node(n)
455115
function clear(node){
    node = get(node);

    while (node[LAST_CHILD])
      node.removeChild(node[LAST_CHILD]);

    return node;
  }
983055
public void remove(Node<E> node)
    {
        lock.writeLock().lock();
        assert node.value != null;
        node.value = null;
        try
        {
            size--;

            // go up through each level in the skip list, unlinking this node; this entails
            // simply linking each neighbour to each other, and appending the size of the
            // current level owned by this node's index to the preceding neighbour (since
            // ownership is defined as any node that you must visit through the index,
            // removal of ourselves from a level means the preceding index entry is the
            // entry point to all of the removed node's descendants)
            for (int i = 0 ; i < node.height() ; i++)
            {
                Node<E> prev = node.prev(i);
                Node<E> next = node.next(i);
                assert prev != null;
                prev.setNext(i, next);
                if (next != null)
                    next.setPrev(i, prev);
                prev.size[i] += node.size[i] - 1;
            }

            // then go up the levels, removing 1 from the size at each height above ours
            for (int i = node.height() ; i < maxHeight ; i++)
            {
                // if we're at our height limit, we backtrack at our top level until we
                // hit a neighbour with a greater height
                while (i == node.height())
                    node = node.prev(i - 1);
                node.size[i]--;
            }
        }
        finally
        {
            lock.writeLock().unlock();
        }
    }
423029
private boolean removeConvertedNodes(AbstractNode node) {
    boolean nodeRemoved = false;
    Iterator<AbstractNode> it = node.getChildren().iterator();
    while (it.hasNext()) {
      FilterJoinNode child = (FilterJoinNode) it.next();
      if (child.getState().equals(FilterJoinNode.State.CONVERTED)) {
        it.remove();
        nodeRemoved |= true;
      }
      else {
        nodeRemoved |= this.removeConvertedNodes(child) ? true : false;
      }
    }
    return nodeRemoved;
  }
539500
void removeAllButDeepestAndAddCacheLeafNodes(int depth) {
        Queue<SchemaTableTree> queue = new LinkedList<>();
        queue.add(this);
        while (!queue.isEmpty()) {
            SchemaTableTree current = queue.remove();
            if (current.stepDepth < depth && current.children.isEmpty() && !current.isEmit() && !current.isOptionalLeftJoin()) {
                removeNode(current);
            } else {
                queue.addAll(current.children);
                if ((current.stepDepth == depth && current.children.isEmpty()) || (current.isEmit() && current.children.isEmpty()) || current.isOptionalLeftJoin() && current.children.isEmpty()) {
                    this.leafNodes.add(current);
                }
            }
        }
    }
411757
private final V remove_node(BinTreeNode<K,V> node, BinTreeNode<K,V> prev, int son) {
	if(node.left == null)
	    return remove_semi_leaf(node, prev, son, node.right);
	if(node.right == null)
	    return remove_semi_leaf(node, prev, son, node.left);

	// The BinTreeNode to replace node in the tree. This is either the
	// next or the precedent node (in the order of the hashCode's.
	// We decide a bit randomly, to gain some balanceness.
	BinTreeNode<K,V> m = 
	    (node.keyHashCode % 2 == 0) ?
	    extract_next(node) : extract_prev(node);

	return finish_removal(node, prev, son, m);
    }
85386
function remove(node, isRemoveChild) {
  if (!node || !node.parentNode) { return; }
  if (node.removeNode) { return node.removeNode(isRemoveChild); }

  const parent = node.parentNode;
  if (!isRemoveChild) {
    const nodes = [];
    for (let i = 0, len = node.childNodes.length; i < len; i++) {
      nodes.push(node.childNodes[i]);
    }

    for (let i = 0, len = nodes.length; i < len; i++) {
      parent.insertBefore(nodes[i], node);
    }
  }

  parent.removeChild(node);
}
875720
function () {
					oNodeForContext.nodeState.removed = false;
					var iNodeStateFound = that._aRemoved.indexOf(oNodeForContext);
					if (iNodeStateFound != -1) {
						that._aRemoved.splice(iNodeStateFound, 1);
					}
					// clear cache to make sure findNode etc. don't deliver wrong nodes (index is shifted due to adding)
					this._aNodeCache = [];
					that._cleanTreeStateMaps();
					that._fireChange({reason: ChangeReason.Add});
				}
603570
def _delete_subtree(self, nodes):
        
        nodes = nodes if isinstance(nodes, list) else [nodes]
        iobj = [
            (self._db[node]["parent"], node)
            for node in nodes
            if self._node_name_in_tree(node)
        ]
        for parent, node in iobj:
            # Delete link to parent (if not root node)
            del_list = self._get_subtree(node)
            if parent:
                self._db[parent]["children"].remove(node)
            # Delete children (sub-tree)
            for child in del_list:
                del self._db[child]
            if self._empty_tree():
                self._root = None
                self._root_hierarchy_length = None
1114649
def cut_levels(nodes, start_level):
    
    final = []
    removed = []
    for node in nodes:
        if not hasattr(node, 'level'):
            # remove and ignore nodes that don't have level information
            remove(node, removed)
            continue
        if node.attr.get('soft_root', False):
            # remove and ignore nodes that are behind a node marked as 'soft_root'
            remove(node, removed)
            continue
        if node.level == start_level:
            # turn nodes that are on from_level into root nodes
            final.append(node)
            node.parent = None
            if not node.visible and not node.children:
                remove(node, removed)
        elif node.level == start_level + 1:
            # remove nodes that are deeper than one level
            node.children = []
        else:
            remove(node, removed)
        if not node.visible:
            keep_node = False
            for child in node.children:
                keep_node = keep_node or child.visible
            if not keep_node:
                remove(node, removed)
    for node in removed:
        if node in final:
            final.remove(node)
    return final
759669
function removeMultiplicationByOne(node) {
  if (node.op !== '*') {
    return Node.Status.noChange(node);
  }
  const oneIndex = node.args.findIndex(arg => {
    return Node.Type.isConstant(arg) && arg.value === '1';
  });
  if (oneIndex >= 0) {
    let newNode = clone(node);
    // remove the 1 node
    newNode.args.splice(oneIndex, 1);
    // if there's only one operand left, there's nothing left to multiply it
    // to, so move it up the tree
    if (newNode.args.length === 1) {
      newNode = newNode.args[0];
    }
    return Node.Status.nodeChanged(
      ChangeTypes.REMOVE_MULTIPLYING_BY_ONE, node, newNode);
  }
  return Node.Status.noChange(node);
}
617942
def prune_node(self, node, remove_backrefs=False):
        
        if not remove_backrefs:
            for fro, connections in self.edges.items():
                if node in self.edges[fro]:
                    raise ValueError("""Attempting to remove a node with
                                     backrefs. You may consider setting
                                     `remove_backrefs` to true.""")

        # OK. Otherwise, let's do our removal.

        self.nodes.remove(node)
        if node in self.edges:
            # Remove add edges from this node if we're pruning it.
            self.edges.pop(node)

        for fro, connections in self.edges.items():
            # Remove any links to this node (if they exist)
            if node in self.edges[fro]:
                # If we should remove backrefs:
                self.edges[fro].remove(node)