Runs a depth-first-search starting at the root node.
320937
public int dfs(int root, boolean isRootT1, boolean[] marked1, boolean[] marked2, BipVisitor<T1,T2> visitor) {
        IntStack sNode = new IntStack();
        ByteStack sIsT1 = new ByteStack(); // TODO: This should be a boolean stack.
        sNode.push(root);
        sIsT1.push((byte)(isRootT1 ? 1 : 0)); 
        
        // The number of times we check if any node is marked. 
        // For acyclic graphs this should be two times the number of nodes.
        int numMarkedChecks = 0;
        
        while (sNode.size() != 0) {
            int node = sNode.pop();
            boolean isT1 = (sIsT1.pop() == 1);            
            if (isT1) {
                // Visit node only if not marked.
                int t1 = node;
                if (!marked1[t1]) {
                    marked1[t1] = true;
                    if (visitor != null) { visitor.visit(t1, true, this); }
                    for (int nb = numNbsT1(t1)-1; nb >= 0; nb--) {
                        int t2 = childT1(t1, nb);
                        if (!marked2[t2]) {
                            sNode.push(t2);
                            sIsT1.push((byte)0);
                        }
                        numMarkedChecks++;
                    }
                }
                numMarkedChecks++;
            } else {
                // Visit node only if not marked.
                int t2 = node;
                if (!marked2[t2]) {
                    marked2[t2] = true;
                    if (visitor != null) { visitor.visit(t2, false, this); }
                    for (int nb = numNbsT2(t2)-1; nb >= 0; nb--) {
                        int t1 = childT2(t2, nb);
                        if (!marked1[t1]) {
                            sNode.push(t1);
                            sIsT1.push((byte)1);
                        }
                        numMarkedChecks++;
                    }
                }
                numMarkedChecks++;
            }
        }
        return numMarkedChecks;
    }
477895
private void stepClosest(KdTree.Node node) {

		if( node == null )
			return;

		if( node.isLeaf() ) {
			// a leaf can be empty.
			if( node.point != null ) {
				double distSq = distance.distance((P)node.point,target);
				if( distSq <= bestDistanceSq ) {
					if( closest == null || distSq < bestDistanceSq ) {
						closest = node;
						bestDistanceSq = distSq;
					}
				}
			}
			return;
		} else {
			double distSq = distance.distance((P)node.point,target);
			if( distSq <= bestDistanceSq ) {
				if( closest == null || distSq < bestDistanceSq ) {
					closest = node;
					bestDistanceSq = distSq;
				}
			}
		}

		// select the most promising branch to investigate first
		KdTree.Node nearer,further;

		double splitValue = distance.valueAt((P)node.point,node.split);

		double targetAtSplit = distance.valueAt(target,node.split);
		if( targetAtSplit	 <= splitValue ) {
			nearer = node.left;
			further = node.right;
		} else {
			nearer = node.right;
			further = node.left;
		}

		stepClosest(nearer);

		// See if it is possible for 'further' to contain a better node
		double dx = splitValue - targetAtSplit;
		double dx2 = dx*dx;
		if( dx2 <= bestDistanceSq ) {
			if( closest == null || dx2 < bestDistanceSq )
				stepClosest(further);
		}
	}
646208
function startNode(node) {
            var navNode = emptyNavigationBarNode(node);
            pushChild(parent, navNode);
            // Save the old parent
            parentsStack.push(parent);
            parent = navNode;
        }
784752
function depth(root) {
	let i = 0;
	let walker = document.createTreeWalker(root, 0xFFFFFFFF, {
		acceptNode: function(node){
			let nt = node.nodeType;
			return nt === 1 || nt === 3;
		}
	});

	while(walker.nextNode()) {
		i++;
	}
	return i;
}
1007683
private static Treenode search(Iterable<Treenode> root, String text, ITreenodeSearch search) {
        for (Treenode node : root) {
            if (search.isMatch(node, text)) {
                return node;
            }
        }
        return null;
    }
876358
def walk(self,depth=0,fsNode=None) :
        """"""
        if not fsNode :
            fsNode = FSNode(self.init_path,self.init_path,0)
            
        if fsNode.isdir() :
            if self.check_dir(fsNode) :
                if self.check_return(fsNode) :
                    yield fsNode                
                for n in fsNode.children() :
                    if n.islink() :
                        # currently we don't follow links
                        continue
                    for n2 in self.walk(depth+1,n) :
                        if self.check_return(n2) :
                            yield n2
        else :
            if self.check_file(fsNode) :
                if self.check_return(fsNode) :
                    yield fsNode
        raise StopIteration
165333
function searchNodeInTree(treeRoot, nodeId){
    if (treeRoot.childNodes){
        for (var i = 0; i < treeRoot.childNodes.length; ++i){
            var currentNode = treeRoot.childNodes[i];
            if (currentNode._id == nodeId){
                return currentNode;
            } else {
                var found = searchNodeInTree(currentNode, nodeId);
                if (found) {
                    return found;
                }
            }
        }
    }
    return false;
}
1167905
public Object depthFirst(NodeVisitor nodeVisitor, Collection<? extends Node> roots) {
        TraverserVisitor<Node> nodeTraverserVisitor = new TraverserVisitor<Node>() {

            @Override
            public TraversalControl enter(TraverserContext<Node> context) {
                context.setVar(LeaveOrEnter.class, LeaveOrEnter.ENTER);
                return context.thisNode().accept(context, nodeVisitor);
            }

            @Override
            public TraversalControl leave(TraverserContext<Node> context) {
                context.setVar(LeaveOrEnter.class, LeaveOrEnter.LEAVE);
                return context.thisNode().accept(context, nodeVisitor);
            }
        };
        return doTraverse(roots, nodeTraverserVisitor);
    }
1287032
function depthFirst(uniqNodes, edges) {
    var nodeIds = Object.keys(uniqNodes);
    var totalNodes = nodeIds.length;
    debug('Found %d unique nodes: %j', totalNodes, nodeIds);

    var sortedNodes = [];
    var markedNodes = {};

    var nodeIndex = 0;
    do {
        var currentNode = uniqNodes[nodeIds[nodeIndex]];

        if (!markedNodes[currentNode.id()]) {
            visit(currentNode, edges, markedNodes, sortedNodes);
        }
    } while (++nodeIndex < totalNodes);

    return sortedNodes;
}
58338
def iter_breadth_first(self, root=None):
        
        if root == None:
            root = self
        yield root
        last = root 
        for node in self.iter_breadth_first(root):
            if isinstance(node, DictCell):
                # recurse
                for subpart in node:
                    yield subpart
                    last = subpart
            if last == node:
                return
497580
def start_node(self):
        
        return db.cypher_query("MATCH (aNode) "
                               "WHERE id(aNode)={nodeid} "
                               "RETURN aNode".format(nodeid=self._start_node_id),
                               resolve_objects = True)[0][0][0]
1355618
def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None):
    """"""
    ordering = []
    parent_lookup = {}
    children_lookup = defaultdict(lambda: [])

    all_nodes = graph.get_all_node_ids()
    if not all_nodes:
        return ordering, parent_lookup, children_lookup

    stack = deque()
    discovered = defaultdict(lambda: False)
    unvisited_nodes = set(all_nodes)

    if root_node is None:
        root_node = all_nodes[0]

    if adjacency_lists is None:
        adj = lambda v: graph.neighbors(v)
    else:
        adj = lambda v: adjacency_lists[v]

    # --Initialize the stack, simulating the DFS call on the root node
    stack.appendleft(root_node)
    parent_lookup[root_node] = root_node

    # We're using a non-recursive implementation of DFS, since Python isn't great for deep recursion
    while True:
        # Main DFS Loop
        while len(stack) > 0:
            u = stack.popleft()

            if not discovered[u]:
                discovered[u] = True
                if u in unvisited_nodes:
                    unvisited_nodes.remove(u)
                ordering.append(u)
                neighbors = adj(u)
                # When adding the new nodes to the stack, we want to add them in reverse order so that
                # the order the nodes are visited is the same as with a recursive DFS implementation
                for n in neighbors[::-1]:
                    if discovered[n]:
                        # If the node already exists in the discovered nodes list
                        # we don't want to re-add it to the stack
                        continue
                    stack.appendleft(n)
                    parent_lookup[n] = u
                    children_lookup[u].append(n)

        # While there are still nodes that need visiting, repopulate the stack
        if len(unvisited_nodes) > 0:
            u = unvisited_nodes.pop()
            stack.appendleft(u)
        else:
            break

    return ordering, parent_lookup, children_lookup
1364832
def run_steps(node: Node, pipeline: RenderingPipeline, **args):
    """"""
    for step in pipeline.steps:
        result = step(node, pipeline=pipeline, **args)
        if isinstance(result, dict):
            args = {**args, **result}
1152247
private void setNodeRecrusively(ZooNode zooNode, int depth) {
        try {
            int currDepth = depth + 1;
            List<String> children = zkClient.getChildren(zooNode.getPath());
            if (CollectionUtils.isEmpty(children)) {
                zooNode.setLeaf(true);
                return;
            }
            for (String name : children) {
                ZooNode node = new ZooNode(ZkPathUtil.buildPath(zooNode.getPath(), name), name);
                if (currDepth < 2) {
                    node.setOpen(true);
                }
                zooNode.getChildren().add(node);
                setNodeRecrusively(node, currDepth);
            }
        } catch (NoNodeException e) {
            LOG.warn("Zookeeper path not found" + e.getMessage(), e);
        } catch (Exception e) {
            LOG.error("Zookeeper get children error" + e.getMessage(), e);
        }
    }
1148553
private void initScopeRoots(Node n) {
    Deque<Node> queuedScopeRoots = new ArrayDeque<>();
    while (n != null) {
      if (isScopeRoot(n)) {
        queuedScopeRoots.addFirst(n);
      }
      n = n.getParent();
    }
    for (Node queuedScopeRoot : queuedScopeRoots) {
      pushScope(queuedScopeRoot);
    }
  }
1270507
def depth_first_recurse(node = nil, depth = 0, &block)
      node = self if node == nil
      yield node, depth
      node.children.each do |child|
        depth_first_recurse(child, depth+1, &block)
      end
    end
403275
public static <T> Iterable<T> depthFirst(TreeDef<T> treeDef, T node) {
		return () -> new Iterator<T>() {
			Deque<T> queue = new ArrayDeque<>(Arrays.asList(node));

			@Override
			public boolean hasNext() {
				return !queue.isEmpty();
			}

			@Override
			public T next() {
				if (queue.isEmpty()) {
					throw new NoSuchElementException();
				}
				T next = queue.removeLast();
				List<T> children = treeDef.childrenOf(next);
				ListIterator<T> iterator = children.listIterator(children.size());
				while (iterator.hasPrevious()) {
					queue.addLast(iterator.previous());
				}
				return next;
			}
		};
	}