Recursive tree traversal function
@param {Object} node
@param {number} depth
@param {number} index
@returns {string}
491687
function recursive (node, depth, index) {
    let hashLeft
    let hashRight
    let summingBuffer

    // case with single node in tree
    if (depth === 0 && node.val !== undefined) {
      return getHash(node.val, depth, index * 2)
    }

    if (node.left === undefined) {
      throw new Error('Left node is missed.')
    }
    if (typeof node.left === 'string') {
      if (!validateHexadecimal(node.left)) {
        throw new TypeError('Tree element of wrong type is passed. Hexadecimal expected.')
      }
      hashLeft = node.left
    } else {
      if (!isObject(node.left)) {
        throw new TypeError('Invalid type of left node.')
      }
      if (node.left.val !== undefined) {
        hashLeft = getHash(node.left.val, depth, index * 2)
      } else {
        hashLeft = recursive(node.left, depth + 1, index * 2)
      }
    }

    if (depth === 0) {
      rootBranch = 'right'
    }

    if (node.right !== undefined) {
      if (typeof node.right === 'string') {
        if (!validateHexadecimal(node.right)) {
          throw new TypeError('Tree element of wrong type is passed. Hexadecimal expected.')
        }
        hashRight = node.right
      } else {
        if (!isObject(node.right)) {
          throw new TypeError('Invalid type of right node.')
        }

        if (node.right.val !== undefined) {
          hashRight = getHash(node.right.val, depth, index * 2 + 1)
        } else {
          hashRight = recursive(node.right, depth + 1, index * 2 + 1)
        }
      }

      summingBuffer = new Uint8Array(64)
      summingBuffer.set(hexadecimalToUint8Array(hashLeft))
      summingBuffer.set(hexadecimalToUint8Array(hashRight), 32)
      return hash(summingBuffer)
    }

    if (depth === 0 || rootBranch === 'left') {
      throw new Error('Right leaf is missed in left branch of tree.')
    }
    summingBuffer = hexadecimalToUint8Array(hashLeft)
    return hash(summingBuffer)
  }
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
1037976
def binaryTree_depthFirstNumbers(binaryTree, labelTree=True, dontStopAtID=True):
    
    traversalIDs = {}
    def traverse(binaryTree, mid=0, leafNo=0):
        if binaryTree.internal and (dontStopAtID or binaryTree.iD is None):
            midStart = mid
            j, leafNo = traverse(binaryTree.left, mid, leafNo)
            mid = j
            j, leafNo = traverse(binaryTree.right, j+1, leafNo)
            traversalIDs[binaryTree] = TraversalID(midStart, mid, j)
            return j, leafNo
        traversalID = TraversalID(mid, mid, mid+1)
        traversalID.leafNo = leafNo
        #thus nodes must be unique
        traversalIDs[binaryTree] = traversalID
        return mid+1, leafNo+1
    traverse(binaryTree)
    if labelTree:
        for binaryTree in traversalIDs.keys():
            binaryTree.traversalID = traversalIDs[binaryTree]
    return traversalIDs
1202314
function traverseNodes(nodes, visitor) {
    const ne = new NodeEventGenerator(visitor)
    traverse(nodes, {
        enter(child) {
            ne.enterNode(child)
        },

        leave(child) {
            ne.leaveNode(child)
        },
    })
}
636688
def get_node(self, index):
        

        if not index.isValid():
            return self.__root_node
        return index.internalPointer() or self.__root_node
490077
function( roots, fn, directed ){
      directed = arguments.length === 1 && !$$.is.fn(fn) ? fn : directed;
      fn = $$.is.fn(fn) ? fn : function(){};
      var cy = this._private.cy;
      var v = $$.is.string(roots) ? this.filter(roots) : roots;
      var Q = [];
      var connectedEles = [];
      var connectedFrom = {};
      var id2depth = {};
      var V = {};
      var j = 0;
      var found;
      var nodes = this.nodes();
      var edges = this.edges();

      // enqueue v
      for( var i = 0; i < v.length; i++ ){
        if( v[i].isNode() ){
          Q.unshift( v[i] );
          V[ v[i].id() ] = true; 

          connectedEles.push( v[i] );
          id2depth[ v[i].id() ] = 0;
        }
      }

      while( Q.length !== 0 ){
        var v = Q.shift();
        var depth = id2depth[ v.id() ];
        var ret = fn.call(v, j++, depth);

        if( ret === true ){
          found = v;
          break;
        }

        if( ret === false ){
          break;
        }

        var vwEdges = v.connectedEdges(directed ? '[source = "' + v.id() + '"]' : undefined).intersect( edges );
        for( var i = 0; i < vwEdges.length; i++ ){
          var e = vwEdges[i];
          var w = e.connectedNodes('[id != "' + v.id() + '"]').intersect( nodes );

          if( w.length !== 0 && !V[ w.id() ] ){
            w = w[0];

            Q.push( w );
            V[ w.id() ] = true;

            id2depth[ w.id() ] = id2depth[ v.id() ] + 1;

            connectedEles.push( w );
            connectedEles.push( e );
          }
        }
        
      }

      return {
        path: new $$.Collection( cy, connectedEles ),
        found: new $$.Collection( cy, found )
      };
    }
1279841
public NodeAVL getNode(int index) {

        NodeAVL n = nPrimaryNode;

        while (index-- > 0) {
            n = n.nNext;
        }

        return n;
    }
812025
def __DepthFirstSearch(node, hashes):
        
        if node.LeftChild is None:
            hashes.add(node.Hash)
        else:
            MerkleTree.__DepthFirstSearch(node.LeftChild, hashes)
            MerkleTree.__DepthFirstSearch(node.RightChild, hashes)
1295349
def deepest_node((subj, pred, obj), graph):
    """"""
    # i don't fully accept the premise that this docstring presents
    # i'm not a docstring literalist
    to_return = []

    def _deepest_node((subj, pred, obj), graph):
        children = []
        if isinstance(obj, rt.BNode):
            for s, p, o in graph:
                if str(s) == str(obj):
                    children.append((s, p, o))
            for s, p, o in children:
                s1, p1, o1 = _deepest_node((s, p, o), graph)
                # coupling *smacks hand with ruler*
                if "rNews" in str(o1) and (s1, p1, o1) not in to_return:
                    to_return.append((s1, p1, o1))
            return (s1, p1, o1)
        else:
            return (subj, pred, obj)
    _deepest_node((subj, pred, obj), graph)

    return to_return
605423
function  (node) {
		  	var parent = node.parentNode,
			  	path = [],
			  	index = this.getChildIndex(node);

		  if(parent && (path = this.getNodePath(parent))){
			   if(index > -1){
				   path.push(index);
			   }
		  }
		  return path;
		}
1076610
function deepChild(root, path) {
  return path.reduce(function (node, index, x) {
    assert(index in node.children, 'child does not exist at the given deep index ' + path.join('.'));
    return node.children[index];
  }, root);
}
519042
def traversal(root):
    ''''''
    stack = [root]
    while len(stack) > 0:
        node = stack.pop()
        if hasattr(node,'children'):
            if node.children == set():
                try:
                    stack[-1].children.remove(node)
                except:
                    pass
                yield (node,stack)
            else:
                childnode = node.children.pop()
                stack += [node,childnode]
        else: 
            children = [x for x in ast.iter_child_nodes(node)]
            node.children = set(children)
            stack.append(node)
1370855
function(nodes) {
        var ans = [], config = this.config, root = this.viz.root;
        nodes.sort(function(a, b) { return (a._depth <= b._depth) - (a._depth >= b._depth); });
        for(var i=0; i<nodes.length; i++) {
            if(nodes[i].anySubnode("exist")) {
            	for (var j = i+1, desc = false; !desc && j < nodes.length; j++) {
                    if(!config.multitree || '$orn' in nodes[j].data) {
                		desc = desc || nodes[i].isDescendantOf(nodes[j].id);                    	
                    }
                }
                if(!desc) ans.push(nodes[i]);
            }
        }
        return ans;
    }
1261916
function(index) {
    var result = _.extend({}, index.nodes);
    _.each(index.scopes, function(child, name) {
      if (name !== "nodes") {
        _.extend(result, _collect(child));
      }
    });
    return result;
  }
1117047
function treeSorter(node) {
    if(node[options.childsProp]) {
      node[options.childsProp].forEach(function(node) {
        treeSorter(node);
      });
      node[options.childsProp].sort(function childSorter(a, b) {
        var result;
        if('undefined' === typeof a[options.sortProp]) {
          result = (options.sortDesc ? 1 : -1);
        } else if('undefined' === typeof b[options.sortProp]) {
          result = (options.sortDesc ? -1 : 1);
        } else {
          result = a[options.sortProp] > b[options.sortProp] ?
            (options.sortDesc ? -1 : 1) : (options.sortDesc ? 1 : -1);
        }
        return result;
      });
    }
  }
829359
Node<E> node(int index) {
        // assert isElementIndex(index);

        if (index < (size >> 1)) {
            Node<E> x = first;
            for (int i = 0; i < index; i++)
                x = x.next;
            return x;
        } else {
            Node<E> x = last;
            for (int i = size - 1; i > index; i--)
                x = x.prev;
            return x;
        }
    }
1036016
function(node, callback, depth) {
			if (this.isSkipped(node)) {
				return;
			}

			var childNode,
				childNodes = node && node.childNodes || [];

			depth = (depth || 1);

			for (var n = 0, len = childNodes.length; n < len; n++) {
				childNode = childNodes[n];

				// callback can return false to stop recursive
				if (callback(childNode, depth) !== false) {
					this.walk(childNode, callback, depth + 1);
				}
			}
		}