Tag each node under root with the appropriate depth.
192303
def tagAttributes_while(fdef_master_list,root):
    ''' '''
    depth = 0
    current = root
    untagged_nodes = [root]
    while untagged_nodes:
        current = untagged_nodes.pop()
        for x in fdef_master_list:
            if jsName(x.path,x.name) == current['name']:
                current['path'] = x.path
        if children in current:
            for child in children:
                child["depth"] = depth
                untagged_nodes.append(child)
        if depth not in current:
            current["depth"] = depth
            depth += 1
    return root
1262686
public void tagPOS(List<CoreLabel> tokens, Tree tree) {
        try {
            List<TaggedWord> posList = tree.getChild(0).taggedYield();
            for (int i = 0; i < tokens.size(); i++) {
                String pos = posList.get(i).tag();
                tokens.get(i).setTag(pos);
            }
        } catch (Exception e) {
            tagPOS(tokens); // At least gives you something.
            LOG.warn("POS Failed:\n" + tree.pennString());
        }
    }
1251883
public static void scanForLeaves(List<RPNode> nodes,RPTree scan) {
        scanForLeaves(nodes,scan.getRoot());
    }
1247449
def tag(self, layer):
        """"""
        mapping = self.layer_tagger_mapping
        if layer in mapping:
            mapping[layer]()
        return self
351333
def BrushForNode( self, node, depth=0 ):
        """"""
        if node == self.selectedNode:
            color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
        elif node == self.highlightedNode:
            color = wx.Colour( red=0, green=255, blue=0 )
        else:
            color = self.adapter.background_color(node, depth)
            if not color:
                red = (depth * 10)%255
                green = 255-((depth * 5)%255)
                blue = (depth * 25)%255
                color = wx.Colour( red, green, blue )
        return wx.Brush( color  )
313053
protected void addContainerTags() {
	// Only add root if we aren't it
	final RootContainer rc = getRootContainer(container);
	if (rc != null) {
	    tags.add(rc);
	}

	final TreeDepth parentDepth = getTreeDepth(container);
	tags.add(parentDepth != null ? parentDepth.increment() : TreeDepth.ROOT);
    }
1189986
private void dfs(Node root) {
        root.setMarked(true);
        for (Edge e : root.getOutEdges()) {
            N n = e.getChild();
            if (!n.isMarked()) {
                dfs(n);
            }
        }
    }
1014135
private void condenseTree(IndexTreePath<E> subtree, Stack<N> stack) {
    N node = getNode(subtree.getEntry());
    // node is not root
    if(!isRoot(node)) {
      N parent = getNode(subtree.getParentPath().getEntry());
      int index = subtree.getIndex();
      if(hasUnderflow(node)) {
        if(parent.deleteEntry(index)) {
          stack.push(node);
        }
        else {
          node.adjustEntry(parent.getEntry(index));
        }
      }
      else {
        node.adjustEntry(parent.getEntry(index));
      }
      writeNode(parent);
      // get subtree to parent
      condenseTree(subtree.getParentPath(), stack);
    }

    // node is root
    else {
      if(hasUnderflow(node) && node.getNumEntries() == 1 && !node.isLeaf()) {
        N child = getNode(node.getEntry(0));
        final N newRoot;
        if(child.isLeaf()) {
          newRoot = createNewLeafNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addLeafEntry(child.getEntry(i));
          }
        }
        else {
          newRoot = createNewDirectoryNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addDirectoryEntry(child.getEntry(i));
          }
        }
        writeNode(newRoot);
        height--;
      }
    }
  }
599695
function walkDomNode(node, functor) {
	if (functor(node.actualNode) !== false) {
		node.children.forEach(child => walkDomNode(child, functor));
	}
}
794101
function(o) {
        for (i in o) {
            if (!!o[i] && typeof(o[i]) == "object") {
                if (!o[i].length && o[i].type === 'tag') {
                    nodeCount += 1;
                    o[i]._id = nodeCount;
                }
                traverseIds(o[i]);
            }
        }
    }
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);
}
761234
function getViewRoot(source) {
	const tokens = parse(source);

	let position = tokens.length;
	let tagDepth = 0;
	let tagName;
	let token;

	/**
	 * Loop backwards through the view's source and find the last closing tag
	 * and its matching opening tag to determine the view's root node position.
	 */
	while (token = tokens[--position]) {
		if (token.type !== TokenTypes.TagStart) {
			continue;
		}

		let tag = parseTag(position, tokens);

		// the last node in the source is a self-closing tag; use that
		if (!tagName && tag.self) {
			break;
		}

		// this is the last tag in the source; save the name and find its pair
		if (!tagName) {
			tagName = tag.name;
			tagDepth++;
			continue;
		}

		// ignore any tags with a different name
		if (tag.name !== tagName) {
			continue;
		}

		// increase tags' depth in the tree for closing tags
		if (!tag.open) {
			tagDepth++;
		}

		// decrease tags' depth in the tree for opening (not self-closing) tags
		if (tag.open && !tag.self) {
			tagDepth--;
		}

		// if the tag's depth reached 0, it means this is the opening tag
		if (tagDepth === 0) {
			break;
		}
	}

	token = tokens[position];

	return token ? token.start : 0;
}
842942
def set_project_nodes(self, root_node, maximum_depth=1):
        

        root_directory = root_node.path
        for parent_directory, directories, files in foundations.walkers.depth_walker(root_directory, maximum_depth):
            if parent_directory == root_directory:
                parent_node = root_node
            else:
                parent_node = foundations.common.get_first_item(
                    [node for node in foundations.walkers.nodes_walker(root_node)
                     if node.family == "Directory" and node.path == parent_directory])

            if not parent_node:
                continue

            paths = [node.path for node in parent_node.children]
            for directory in sorted(directories):
                if directory.startswith("."):
                    continue

                path = os.path.join(parent_directory, directory)
                if path in paths:
                    continue

                directory_node = self.register_directory(path, parent_node)

            for file in sorted(files):
                if file.startswith("."):
                    continue

                path = os.path.join(parent_directory, file)
                if path in paths:
                    continue

                if foundations.io.is_readable(path):
                    if foundations.io.is_binary_file(path):
                        continue

                file_node = self.register_file(path, parent_node)
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
46647
def tree(path, depth=2, topdown=True, followlinks=False, showhidden=False):
    """"""
    rt = []
    for root, dirs, files in os.walk(path, topdown=topdown, followlinks=followlinks):
        if not showhidden and File.is_hidden(root):
            continue

        current_depth = len(os.path.relpath(root, path).split(os.sep))
        if current_depth > depth:
            continue

        if showhidden:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs],
                [File(os.path.join(root, _file)) for _file in files]
            )
        else:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs if _dir[0] != '.'],
                [File(os.path.join(root, _file)) for _file in files if _file[0] != '.']
            )

        rt.append(_tuple)
    return rt
807714
function(node, lines, parentName, depth) {

    // Default depth.
    if (_.isUndefined(depth)) {
      depth = 0;
    }

    // Default parentName.
    if (_.isUndefined(parentName)) {
      parentName = 'root';
    }

    if (isTask(node)) {

      // This is a task so add to lines and nothing further.
      lines.push({
        depth: depth,
        name: getName(node),
        parentName: parentName,
        description: node.description
      });

    } else if (isBranch(node)) {

      lines.push({
        depth: depth,
        name: getName(node),
        parentName: parentName
      });
      node.children.forEach(function(child) {
        recAdd(child, lines, getName(node), depth + 1);
      });

    } else {

      // This should never happen.
      assert(false);

    }

  }
164746
private void colorizeTags(Area root, String type)
    {
        recursiveColorizeTags(root, type);
        browser.updateDisplay();
    }