Given a node, recursively enumerate its adjacencies
        until we reach the specified depth (>0).

        Args:
            node:   natlas_node object to enumerate.
            depth:  The depth left that we can go further away from the root.
173140
def __discover_node(self, node, depth):
        '''
        
        '''
        if (node == None):
            return

        if (depth >= self.max_depth):
            return

        if (node.discovered > 0):
            return
        node.discovered = 1

        # vmware ESX can report IP as 0.0.0.0
        # If we are allowing 0.0.0.0/32 in the config,
        # then we added it as a leaf, but don't discover it
        if (node.ip[0] == '0.0.0.0'):
            return

        # may be a leaf we couldn't connect to previously
        if (node.snmpobj.success == 0):
            return

        # print some info to stdout
        dcodes = DCODE_STEP_INTO
        if (depth == 0):
            dcodes |= DCODE_ROOT
        self.__print_step(node.ip[0], node.name, depth, dcodes)

        # get the cached snmp credentials
        snmpobj = node.snmpobj

        # list of valid neighbors to discover next
        valid_neighbors = []

        # get list of neighbors
        cdp_neighbors  = node.get_cdp_neighbors()
        lldp_neighbors = node.get_lldp_neighbors()
        neighbors      = cdp_neighbors + lldp_neighbors
        if (len(neighbors) == 0):
            return

        for n in neighbors:
            # some neighbors may not advertise IP addresses - default them to 0.0.0.0
            if (n.remote_ip == None):
                n.remote_ip = '0.0.0.0'

            # check the ACL
            acl_action = self.__match_node_acl(n.remote_ip, n.remote_name)
            if (acl_action == 'deny'):
                # deny inclusion of this node
                continue
            
            dcodes = DCODE_DISCOVERED
            child = None
            if (acl_action == 'include'):
                # include this node but do not discover it
                child    = natlas_node()
                child.ip = [n.remote_ip]
                dcodes  |= DCODE_INCLUDE
            else:
                # discover this node
                child, query_result = self.__query_node(n.remote_ip, n.remote_name)

            # if we couldn't pull info from SNMP fill in what we know
            if (child.snmpobj.success == 0):
                child.name = util.shorten_host_name(n.remote_name, self.config.host_domains)
                dcodes  |= DCODE_ERR_SNMP
            
            # need to check the ACL again for extended ops (we have more info)
            acl_action = self.__match_node_acl(n.remote_ip, n.remote_name, n.remote_plat, n.remote_ios, child.serial)
            if (acl_action == 'deny'):
                continue

            if (query_result == NODE_NEW):
                self.nodes.append(child)
                if (acl_action == 'leaf'):          dcodes |= DCODE_LEAF
                if (n.discovered_proto == 'cdp'):   dcodes |= DCODE_CDP
                if (n.discovered_proto == 'lldp'):  dcodes |= DCODE_LLDP
                self.__print_step(n.remote_ip, n.remote_name, depth+1, dcodes)

            # CDP/LLDP advertises the platform
            child.plat = n.remote_plat
            child.ios  = n.remote_ios
            
            # add the discovered node to the link object and link to the parent
            n.node = child
            self.__add_link(node, n)

            # if we need to discover this node then add it to the list
            if ((query_result == NODE_NEW) & (acl_action != 'leaf') & (acl_action != 'include')):
                valid_neighbors.append(child)

        # discover the valid neighbors
        for n in valid_neighbors:
            self.__discover_node(n, depth+1)
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
1349303
def reachable_nodes_reverse(self, p_id, p_recursive=True):
        
        return self.reachable_nodes(p_id, p_recursive, True)
291824
def descendants(self, start, generations=None):
        
        visited = self.vertex_set()
        visited.add(start)
        to_visit = deque([(start, 0)])
        while to_visit:
            vertex, depth = to_visit.popleft()
            if depth == generations:
                continue
            for child in self.children(vertex):
                if child not in visited:
                    visited.add(child)
                    to_visit.append((child, depth+1))
        return self.full_subgraph(visited)
1031163
def depth_score_helper(self, d, dopt):
        
        # di is how may levels deeper than optimal d is
        di = d - dopt
        if di > 0:
            count = di * len(self.s_center)
        else:
            count = 0
        if self.right_node:
            count += self.right_node.depth_score_helper(d + 1, dopt)
        if self.left_node:
            count += self.left_node.depth_score_helper(d + 1, dopt)
        return count
941049
def items_at(self, depth):
        
        if depth < 1:
            yield ROOT, self
        elif depth == 1:
            for key, value in self.items():
                yield key, value
        else:
            for dict_tree in self.values():
                for key, value in dict_tree.items_at(depth - 1):
                    yield key, value
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;
}
429893
function depthFirst(node, parent) {
  var results = [];
  if (node && (typeof node === 'object')) {

    // valid node so push it to the list and set new parent
    //  don't overwrite parent if one was not given
    if ('type' in node) {
      if (parent !== undefined) {
        node.parent = parent;
      }
      parent = node;
      results.push(node);
    }

    // recurse object members using nested function call
    for (var key in node) {
      if (WHITE_LIST.test(key)) {
        var value = node[key];
        if (value && (typeof value === 'object')) {
          results.push.apply(results, depthFirst(value, parent));
        }
      }
    }
  }
  return results;
}
473730
def adjacency(tree):
    
    dd = ids(tree)
    N = len(dd)
    A = np.zeros((N, N))

    def _adj(node):
        if np.isscalar(node):
            return
        elif isinstance(node, tuple) and len(node) == 2:
            A[dd[node], dd[node[0]]] = 1
            A[dd[node[0]], dd[node]] = 1
            _adj(node[0])

            A[dd[node], dd[node[1]]] = 1
            A[dd[node[1]], dd[node]] = 1
            _adj(node[1])

    _adj(tree)
    return A
130131
def build_tree(X, y, criterion, max_depth, current_depth=1):
    

    # check for max_depth accomplished
    if max_depth >= 0 and current_depth >= max_depth:
        return Leaf(y)

    # check for 0 gain
    gain, question = find_best_question(X, y, criterion)
    if gain == 0:
        return Leaf(y)

    # split
    true_X, false_X, true_y, false_y = split(X, y, question)

    # Build the `true` branch of the tree recursively
    true_branch = build_tree(
        true_X, true_y,
        criterion,
        max_depth,
        current_depth=current_depth+1
    )
    
    # Build the `false` branch of the tree recursively
    false_branch = build_tree(
        false_X, false_y,
        criterion,
        max_depth,
        current_depth=current_depth+1
    )

    # returning the root of the tree/subtree
    return Node(
        question=question,
        true_branch=true_branch,
        false_branch=false_branch
    )
50625
def n_list(self, node):
        
        p = self.prec
        self.prec = 100
        n = node.pop()
        lastnode = n.kind
        start = len(self.f.getvalue())
        if lastnode.startswith('BUILD_LIST'):
            self.write('['); endchar = ']'
        elif lastnode.startswith('BUILD_TUPLE'):
            self.write('('); endchar = ')'
        elif lastnode.startswith('BUILD_SET'):
            self.write('{'); endchar = '}'
        elif lastnode.startswith('ROT_TWO'):
            self.write('('); endchar = ')'
        else:
            raise RuntimeError('Internal Error: n_list expects list or tuple')

        flat_elems = []
        for elem in node:
            if elem == 'expr1024':
                for subelem in elem:
                        for subsubelem in subelem:
                            flat_elems.append(subsubelem)
            elif elem == 'expr32':
                for subelem in elem:
                    flat_elems.append(subelem)
            else:
                flat_elems.append(elem)

        self.indent_more(INDENT_PER_LEVEL)
        if len(node) > 3:
            line_separator = ',\n' + self.indent
        else:
            line_separator = ', '
        sep = INDENT_PER_LEVEL[:-1]

        # FIXME:
        # if flat_elems > some_number, then group
        # do automatic wrapping
        for elem in flat_elems:
            if (elem == 'ROT_THREE'):
                continue

            assert elem == 'expr'
            value = self.traverse(elem)
            self.node_append(sep, value, elem)
            sep = line_separator
        if len(node) == 1 and lastnode.startswith('BUILD_TUPLE'):
            self.write(',')
        self.write(endchar)
        finish = len(self.f.getvalue())
        n.parent = node.parent
        self.set_pos_info(n, start, finish)
        self.set_pos_info(node, start, finish)
        self.indent_less(INDENT_PER_LEVEL)
        self.prec = p
        self.prune()
        return
1197463
private void checkCoverTree(Node cur, int[] counts, int depth) {
    counts[0] += 1; // Node count
    counts[1] += depth; // Sum of depth
    counts[2] = depth > counts[2] ? depth : counts[2]; // Max depth
    counts[3] += cur.singletons.size() - 1;
    counts[4] += cur.singletons.size() - (cur.children == null ? 0 : 1);
    if(cur.children != null) {
      ++depth;
      for(Node chi : cur.children) {
        checkCoverTree(chi, counts, depth);
      }
      assert (!cur.children.isEmpty()) : "Empty childs list.";
    }
  }
676514
private void traverseClassMembers(Node n) {
    for (Node child = n.getFirstChild(); child != null;) {
      Node next = child.getNext(); // see traverseChildren
      if (child.isComputedProp()) {
        curNode = n;
        if (callback.shouldTraverse(this, child, n)) {
          traverseBranch(child.getLastChild(), child);
          curNode = n;
          callback.visit(this, child, n);
        }
      } else {
        traverseBranch(child, n);
      }
      child = next;
    }
  }
955690
def reachable_nodes(self, p_id, p_recursive=True, p_reverse=False):
        
        stack = [p_id]
        visited = set()
        result = set()

        while len(stack):
            current = stack.pop()

            if current in visited or current not in self._edges:
                continue

            visited.add(current)

            if p_reverse:
                parents = [node for node, neighbors in self._edges.items()
                           if current in neighbors]

                stack = stack + parents
                result = result.union(parents)
            else:
                stack = stack + list(self._edges[current])
                result = result.union(self._edges[current])

            if not p_recursive:
                break

        return result
166936
def query(self, u, v):
        
        # -- assume w.l.o.g. that v is not higher than u in the tree
        if self.level[u] > self.level[v]:
            u, v = v, u
        # -- put v at the same level as u
        depth = len(self.anc)
        for k in range(depth-1, -1, -1):
            if self.level[u] <= self.level[v] - (1 << k):
                v = self.anc[k][v]
        assert self.level[u] == self.level[v]
        if u == v:
            return u
        # -- climb until the lowest common ancestor
        for k in range(depth-1, -1, -1):
            if self.anc[k][u] != self.anc[k][v]:
                u = self.anc[k][u]
                v = self.anc[k][v]
        assert self.anc[0][u] == self.anc[0][v]
        return self.anc[0][u]
1353001
function recurse(data, depth, nodes) {
    var childs = children.call(hierarchy, data, depth),
        node = d3_layout_hierarchyInline ? data : {data: data};
    node.depth = depth;
    nodes.push(node);
    if (childs && (n = childs.length)) {
      var i = -1,
          n,
          c = node.children = [],
          v = 0,
          j = depth + 1,
          d;
      while (++i < n) {
        d = recurse(childs[i], j, nodes);
        d.parent = node;
        c.push(d);
        v += d.value;
      }
      if (sort) c.sort(sort);
      if (value) node.value = v;
    } else if (value) {
      node.value = +value.call(hierarchy, data, depth) || 0;
    }
    return node;
  }
1047408
def convert_depthtospace(node, **kwargs):
    
    name, input_nodes, attrs = get_inputs(node, kwargs)

    blksize = int(attrs.get("block_size", 0))

    node = onnx.helper.make_node(
        "DepthToSpace",
        input_nodes,
        [name],
        blocksize=blksize,
        name=name,
    )
    return [node]