// Returns a slice of Node[] of from 0 to len(nodes) nodes.
// If size is < len(nodes), that many nodes are randomly chosen and
// returned.
334602
func (m *nodeMap) getRandomNodes(size int, exclude ...*Node) []*Node {
	allNodes := m.values()

	if size == 0 {
		size = len(allNodes)
	}

	// First, shuffle the allNodes slice
	for i := range allNodes {
		j := rand.Intn(i + 1)
		allNodes[i], allNodes[j] = allNodes[j], allNodes[i]
	}

	// Copy the first size nodes that are not otherwise excluded
	filtered := make([]*Node, 0, len(allNodes))

	// Horribly inefficient. Fix this later.

	var c int
Outer:
	for _, n := range allNodes {
		// Is the node in the excluded list?
		for _, e := range exclude {
			if n.Address() == e.Address() {
				continue Outer
			}
		}

		// Now we can append it
		filtered = append(filtered, n)
		c++

		if c >= size {
			break Outer
		}
	}

	return filtered
}
347235
func ReplaceRandomConsecutiveNodesWildcard(num int) func(in string) string {
	return func(in string) string {
		parts := strings.Split(in, ".")
		if len(parts) < num {
			log.Fatalf("metric %q has not enough nodes to replace %d nodes", in, num)
		}
		pos := rand.Intn(len(parts) - num + 1)
		for i := pos; i < pos+num; i++ {
			parts[pos] = "*"
		}
		return strings.Join(parts, ".")
	}
}
730849
func Nodes(sel interface{}, nodes *[]*cdp.Node, opts ...QueryOption) Action {
	if nodes == nil {
		panic("nodes cannot be nil")
	}

	return QueryAfter(sel, func(ctx context.Context, n ...*cdp.Node) error {
		*nodes = n
		return nil
	}, opts...)
}
372909
func (c *Client) ListNodes() (rec []NodeInfo, err error) {
	req, err := newGETRequest(c, "nodes")
	if err != nil {
		return []NodeInfo{}, err
	}

	if err = executeAndParseRequest(c, req, &rec); err != nil {
		return nil, err
	}

	return rec, nil
}
147087
func (self *Tree) GetNodesAtHeight(h uint64) []Node {
	if self.Levels == nil || h == 0 || h > uint64(len(self.Levels)) {
		return nil
	} else {
		return self.Levels[h-1]
	}
}
641497
func (n *node) sortChildren() {
	sort.Slice(n.children, func(i, j int) bool {
		a := n.children[i]
		b := n.children[j]
		return a.isParameter() && b.isParameter() && a.re != nil ||
			!a.isParameter() && b.isParameter() ||
			a.countChildren() > b.countChildren()
	})
}
842871
func nodeFromBytes(t *Tr, data []byte) (*Node, error) {
	n := &Node{}
	_, err := n.UnmarshalMsg(data)
	if err != nil {
		panic(err)
		return nil, err
	}

	return n, nil
}
1146300
func (net *Network) getRandomUpNode(excludeIDs ...enode.ID) *Node {
	return net.getRandomNode(net.getUpNodeIDs(), excludeIDs)
}
996235
func (endpoints EndpointList) Nodes() int {
	uniqueNodes := set.NewStringSet()
	for _, endpoint := range endpoints {
		if uniqueNodes.Contains(endpoint.Host) {
			continue
		}
		uniqueNodes.Add(endpoint.Host)
	}
	return len(uniqueNodes)
}
16337
func (b *Bucket) Nodes() []Node {
	b.RLock()
	defer b.RUnlock()
	ret := *(*[]Node)(b.nodeList)
	return ret
}
230363
func (n *Node) Flatten() []*Node {
	nodes := make([]*Node, 0)
	for _, node := range n.Node.Nodes {
		if node.Dir {
			nodes = append(nodes, NewNode(node).Flatten()...)
			continue
		}

		nodes = append(nodes, NewNode(node))
	}

	return nodes
}
167582
func (n *TreeNode) Size() int {
	s := len(n.Values)
	for _, c := range n.Children {
		s += c.Size()
	}
	return s
}
755318
func (tab *Table) ReadRandomNodes(buf []*enode.Node) (n int) {
	if !tab.isInitDone() {
		return 0
	}
	tab.mutex.Lock()
	defer tab.mutex.Unlock()

	// Find all non-empty buckets and get a fresh slice of their entries.
	var buckets [][]*node
	for _, b := range &tab.buckets {
		if len(b.entries) > 0 {
			buckets = append(buckets, b.entries)
		}
	}
	if len(buckets) == 0 {
		return 0
	}
	// Shuffle the buckets.
	for i := len(buckets) - 1; i > 0; i-- {
		j := tab.rand.Intn(len(buckets))
		buckets[i], buckets[j] = buckets[j], buckets[i]
	}
	// Move head of each bucket into buf, removing buckets that become empty.
	var i, j int
	for ; i < len(buf); i, j = i+1, (j+1)%len(buckets) {
		b := buckets[j]
		buf[i] = unwrapNode(b[0])
		buckets[j] = b[1:]
		if len(b) == 1 {
			buckets = append(buckets[:j], buckets[j+1:]...)
		}
		if len(buckets) == 0 {
			break
		}
	}
	return i + 1
}
103809
func (c *Chain) Nodes() (nodes []Node) {
	for _, group := range c.nodeGroups {
		if ns := group.Nodes(); len(ns) > 0 {
			nodes = append(nodes, ns[0])
		}
	}
	return
}
1156481
func sumNodes(ns nodes) (flat int64, cum int64) {
	for _, n := range ns {
		flat += n.flat
		cum += n.cum
	}
	return
}
666486
func Slice(list, start, end cty.Value) (cty.Value, error) {
	return SliceFunc.Call([]cty.Value{list, start, end})
}
160370
func Slice(slice interface{}) {
	rv := reflect.ValueOf(slice)
	swap := reflect.Swapper(slice)
	n := rv.Len()
	for i := n - 1; i >= 0; i-- {
		j := rand.Intn(i + 1)
		swap(i, j)
	}
}