Returns a recursive iterator over all Nodes under top.
    
    If skiphidden is True (the default) then structure branches starting with
    an underscore will be ignored.
508125
def walknode(top, skiphidden=True):
    
    if skiphidden and top.name.startswith('._'):
        return
        
    yield top
    for child in top:
        for c in walknode(child):
            yield c
204757
def traverse(node, on_enter=None, on_leave=None):
    
    node_type = NodeType(node['type'])

    if node_type not in ChildNodeAccessorMap:
        raise UnknownNodeTypeException(node_type)

    if on_enter:
        should_traverse_children = on_enter(node) is not SKIP_CHILDREN
    else:
        should_traverse_children = True

    if should_traverse_children:
        for property_accessor in ChildNodeAccessorMap[node_type]:
            accessor_func = property_accessor['accessor']
            prop_name = property_accessor['property_name']

            accessor_func(lambda child_node: traverse(child_node, on_enter, on_leave),
                          node[prop_name])

        for handler in _traverser_extensions:
            handler(node, on_enter=on_enter, on_leave=on_leave)

    if on_leave:
        on_leave(node)
1333346
def each_recursive(&block) # :yields: node
      self.elements.each {|node|
        block.call(node)
        node.each_recursive(&block)
      }
    end
1039719
def _iter_descendants_levelorder(self, is_leaf_fn=None):
        
        tovisit = deque([self])
        while len(tovisit) > 0:
            node = tovisit.popleft()
            yield node
            if not is_leaf_fn or not is_leaf_fn(node):
                tovisit.extend(node.children)
619109
def traverse_levelorder(self, leaves=True, internal=True):
        ''''''
        for node in self.root.traverse_levelorder(leaves=leaves, internal=internal):
            yield node
1247767
public Iterable<Entry<String, ProfileNode>> getDescendingOrderedNodes() {
			if( nodes == null ) return null;
			
			List<Entry<String, ProfileNode>> averageStepTimes = new LinkedList<Entry<String, ProfileNode>>(nodes.entrySet());
			
			Collections.sort(averageStepTimes, new Comparator<Entry<String, ProfileNode>>() {
				public int compare(Entry<String, ProfileNode> o1, Entry<String, ProfileNode> o2) {
					return (int) (o1.getValue().totalMillisecs - o2.getValue().totalMillisecs);
				}
			});
			
			
			return averageStepTimes;
	}
360690
@Override
  public final Iterable<T> children(final T root) {
    checkNotNull(root);
    return new FluentIterable<T>() {
      @Override
      public Iterator<T> iterator() {
        return new AbstractIterator<T>() {
          boolean doneLeft;
          boolean doneRight;

          @Override
          protected T computeNext() {
            if (!doneLeft) {
              doneLeft = true;
              Optional<T> left = leftChild(root);
              if (left.isPresent()) {
                return left.get();
              }
            }
            if (!doneRight) {
              doneRight = true;
              Optional<T> right = rightChild(root);
              if (right.isPresent()) {
                return right.get();
              }
            }
            return endOfData();
          }
        };
      }
    };
  }
970674
public Iterable<SimpleXmlNode> getDescendents() {
    return new Iterable<SimpleXmlNode>() {
      @Override
      public Iterator<SimpleXmlNode> iterator() {
        return new DescendentsIterator(SimpleXmlNode.this);
      }
    };
  }
1143543
def subtree(self, matcher, create = False):
        '''
        
        '''
        if matcher is None:
            return self
        current = self
        for i in range(self.depth, len(matcher.indices)):
            ind = matcher.indices[i]
            if ind is None:
                # match Any
                if hasattr(current, 'any'):
                    current = current.any
                else:
                    if create:
                        cany = MatchTree(current)
                        cany.parentIndex = None
                        current.any = cany
                        current = cany
                    else:
                        return None
            else:
                current2 = current.index.get(ind)
                if current2 is None:
                    if create:
                        cind = MatchTree(current)
                        cind.parentIndex = ind 
                        current.index[ind] = cind
                        current = cind
                    else:
                        return None
                else:
                    current = current2
        return current
13373
def recursive_children
      self.children.each do |child|
        if Parser::AST::Node === child
          yield child
          child.recursive_children { |c| yield c }
        end
      end
    end
342925
public static <N extends AbstractDTNode<?, ?, ?, N>> Iterator<N> leafIterator(N root) {
        return Iterators.filter(nodeIterator(root), AbstractDTNode::isLeaf);
    }
897814
def traverse(node=nil, &block)
      return self.to_enum unless block_given?
      node_stack = [node || self]
      until node_stack.empty?
        current = node_stack.shift
        if current
          yield current
          node_stack = node_stack.insert(0, *current.nodes) if current.respond_to?(:nodes)
        end
      end
      node || self if block_given?
    end
187708
public static <T> Iterable<T> toParent(TreeDef.Parented<T> treeDef, T node) {
		return () -> new Iterator<T>() {
			T tip = node;

			@Override
			public boolean hasNext() {
				return tip != null;
			}

			@Override
			public T next() {
				if (tip == null) {
					throw new NoSuchElementException();
				}
				T next = tip;
				tip = treeDef.parentOf(tip);
				return next;
			}
		};
	}
717350
def t(root, children=None, debug=False, root_id=None):
    ""
    if isinstance(root, Tree):
        if children is None:
            return root
        return root.__class__(root, children, root_id)

    elif isinstance(root, basestring):
        root = debug_root_label(root, debug, root_id)

        # Beware: (DGParented)Tree is a subclass of list!
        if isinstance(children, Tree):
            child_trees = [children]

        elif isinstance(children, list):
            child_trees = []
            for child in children:
                if isinstance(child, Tree):
                    child_trees.append(child)
                elif isinstance(child, list):
                    child_trees.extend(child)
                elif isinstance(child, tuple):
                    child_trees.append(t(*child))
                elif isinstance(child, basestring):
                    child_trees.append(child)
                else:
                    raise NotImplementedError

        elif isinstance(children, basestring):
            # this tree does only have one child, a leaf node
            # TODO: this is a workaround for the following problem:
            # Tree('foo', [Tree('bar', [])]) != Tree('foo', ['bar'])
            child_trees = [Tree(children, [])]

        else:
            # this tree only consists of one leaf node
            assert children is None
            child_trees = []

        return DGParentedTree(root, child_trees, root_id)

    else:
        raise NotImplementedError
721964
def traverse_levelorder(self, leaves=True, internal=True):
        '''
        '''
        q = deque(); q.append(self)
        while len(q) != 0:
            n = q.popleft()
            if (leaves and n.is_leaf()) or (internal and not n.is_leaf()):
                yield n
            q.extend(n.children)
302987
function topLevelNodeBefore(node, top) {
    while (!node.previousSibling && node.parentNode != top)
      node = node.parentNode;
    return topLevelNodeAt(node.previousSibling, top);
  }
224435
public Iterator iterator() {
        return new Iterator() {
            private LeftTupleSinkNode currentNode = null;
            private LeftTupleSinkNode nextNode    = getFirst();

            public boolean hasNext() {
                return (this.nextNode != null);
            }

            public Object next() {
                this.currentNode = this.nextNode;
                if ( this.currentNode != null ) {
                    this.nextNode = this.currentNode.getNextLeftTupleSinkNode();
                } else {
                    throw new NoSuchElementException( "No more elements to return" );
                }
                return this.currentNode;
            }

            public void remove() {
                if ( this.currentNode != null ) {
                    LeftTupleSinkNodeList.this.remove( this.currentNode );
                    this.currentNode = null;
                } else {
                    throw new IllegalStateException( "No item to remove. Call next() before calling remove()." );
                }
            }
        };
    }