// FindNodes - recursively find nodes
517492
func FindNodes(input *html.Node, match Matcher, callback MatcherCallback) {
	for c := input.FirstChild; c != nil; c = c.NextSibling {
		if match(c.Type, c.DataAtom) {
			callback(c)
		}
		FindNodes(c, match, callback)
	}
}
486083
func (s *Server) SearchNodes(c context.Context, n *pb.Node) (*pb.SearchResult, error) {
	s.RLock()
	defer s.RUnlock()

	var filter []string
	if n.Id != 0 {
		filter = append(filter, fmt.Sprintf("id=%d", n.Id))
	}
	if n.Meta != "" {
		filter = append(filter, fmt.Sprintf("meta~=%s", n.Meta))
	}
	if len(n.Tiers) > 0 {
		for _, v := range n.Tiers {
			filter = append(filter, fmt.Sprintf("tier~=%s", v))
		}
	}
	if len(n.Addresses) > 0 {
		for _, v := range n.Addresses {
			filter = append(filter, fmt.Sprintf("address~=%s", v))
		}
	}
	s.ctxlog.Println("filter:", filter)
	nodes, err := s.r.Nodes().Filter(filter)
	res := make([]*pb.Node, len(nodes))
	if err != nil {
		return &pb.SearchResult{Nodes: res}, err
	}
	for i, n := range nodes {
		if n == nil {
			continue
		}
		res[i] = &pb.Node{
			Id:        n.ID(),
			Active:    n.Active(),
			Capacity:  n.Capacity(),
			Tiers:     n.Tiers(),
			Addresses: n.Addresses(),
			Meta:      n.Meta(),
			Conf:      n.Config(),
		}
	}
	return &pb.SearchResult{Nodes: res}, nil
}
644705
func (t *stringTree) FindAll(f func(v string) (bool, error)) []StringChanger {
	ns, err := t.container.root.findAll(func(fn *node) (bool, error) {
		return f(fn.content.value().(string))
	})
	if err != nil {
		return []StringChanger{&stringChanger{nil, err}}
	}
	var cs []StringChanger
	for _, n := range ns {
		cs = append(cs, &stringChanger{n, nil})
	}
	return cs
}
466870
func (group *NodeGroup) SetNodes(nodes ...Node) []Node {
	if group == nil {
		return nil
	}

	group.mux.Lock()
	defer group.mux.Unlock()

	old := group.nodes
	group.nodes = nodes
	return old
}
822158
func (g *BuilderGroup) Nodes() []*BuilderNode {
	nodes := []*BuilderNode{}
	for node, group := range g.builder.ring.NodeToGroup {
		if group == g.index {
			nodes = append(nodes, g.builder.nodes[node])
		}
	}
	return nodes
}
889404
func (n *node) findAll(f func(fn *node) (bool, error)) ([]*node, error) {
	var allFound []*node
	hasFound, err := f(n)
	if err != nil {
		return nil, errors.Annotate(err, ErrNodeFindAll, errorMessages)
	}
	if hasFound {
		allFound = append(allFound, n)
	}
	for _, child := range n.children {
		found, err := child.findAll(f)
		if err != nil {
			return nil, errors.Annotate(err, ErrNodeFindAll, errorMessages)
		}
		if found != nil {
			allFound = append(allFound, found...)
		}
	}
	return allFound, nil
}
135262
func (e *Element) GetChildNodeIds() ([]int, error) {
	e.lock.RLock()
	defer e.lock.RUnlock()

	if !e.ready {
		return nil, &ElementNotReadyErr{}
	}

	if e.node == nil || e.node.Children == nil {
		return nil, &ElementHasNoChildrenErr{}
	}

	ids := make([]int, len(e.node.Children))
	for k, child := range e.node.Children {
		ids[k] = child.NodeId
	}
	return ids, nil
}
695835
func (ncs *nodeCacheStandard) AllNodes() (nodes []Node) {
	ncs.lock.RLock()
	defer ncs.lock.RUnlock()
	nodes = make([]Node, 0, len(ncs.nodes))
	for _, entry := range ncs.nodes {
		nodes = append(nodes, ncs.makeNodeStandardForEntryLocked(entry))
	}
	return nodes
}
313988
func (tc *TreeCache) findNode(path string) (*TreeNode, error) {
	if !strings.HasPrefix(path, tc.root.path) {
		return nil, ErrRootNotMatch
	}

	path = strings.TrimPrefix(path, tc.root.path)
	current := tc.root
	for _, part := range strings.Split(path, "/") {
		if part == "" {
			continue
		}
		next, exists := current.FindChild(part)
		if !exists {
			return nil, ErrNodeNotFound
		}
		current = next
	}

	return current, nil
}
932028
func (Ctx *Context) GetMaxNodes() (maxNodes int, err error) {
	err = Ctx.CheckOpen()
	if err != nil {
		return
	}
	ret := C.libxl_get_max_nodes(Ctx.ctx)
	if ret < 0 {
		err = Error(-ret)
		return
	}
	maxNodes = int(ret)
	return
}
683340
func containsNode(node, x ast.Node) (found bool) {
	ast.Walk(funcVisitor(func(n ast.Node) bool {
		if !found {
			found = n == x
		}
		return !found
	}),
		node)
	return
}
289852
func (net *Network) GetNodes() (nodes []*Node) {
	net.lock.RLock()
	defer net.lock.RUnlock()

	return net.getNodes()
}
1192690
func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection {
	set := make(map[*html.Node]bool)
	for _, n := range nodes {
		set[n] = true
	}
	return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
		// For each node in the selection, test the node itself, then each parent
		// until a match is found.
		for ; n != nil; n = n.Parent {
			if set[n] {
				return []*html.Node{n}
			}
		}
		return nil
	}))
}
329443
func FindAll(node *parser.Node, cmd string) []int {
	if node == nil {
		return nil
	}
	var indices []int
	for i, child := range node.Children {
		if child != nil && child.Value == cmd {
			indices = append(indices, i)
		}
	}
	return indices
}
365630
func (treeNode *TreeNode) Search(patternNode PatternNode) []*TreeNode {
	results := []*TreeNode{}

	// Current node
	if treeNode.compare(patternNode) {
		results = append(results, treeNode)
	}

	// Current node's children
	for _, child := range treeNode.Children {
		for _, subResult := range child.Search(patternNode) {
			results = append(results, subResult)
		}
	}

	return results
}
1152629
func (d *dir) find(q string) node {
	q = strings.Trim(q, "/")
	i := strings.Index(q, "/")

	if q == "" {
		return d
	}

	if i == 0 {
		panic("shouldn't happen, no root paths")
	}

	var component string
	if i < 0 {
		// No more path components
		component = q
	} else {
		component = q[:i]
	}

	child, ok := d.children[component]
	if !ok {
		// Node was not found. Return p and the current node.
		return d
	}

	if child.isdir() {
		// traverse down!
		q = q[i+1:]
		return child.(*dir).find(q)
	}

	return child
}
337508
func (l *level) numNodes() int {
	num := len(l.nodes)
	if l.pwc != nil {
		num++
	}
	if l.fwc != nil {
		num++
	}
	return num
}