// This will add in a node's results to the total results.
507540
func addNodeToResults(n *node, results *SublistResult) {
	// Normal subscriptions
	if n.plist != nil {
		results.psubs = append(results.psubs, n.plist...)
	} else {
		for _, psub := range n.psubs {
			results.psubs = append(results.psubs, psub)
		}
	}
	// Queue subscriptions
	for qname, qr := range n.qsubs {
		if len(qr) == 0 {
			continue
		}
		// Need to find matching list in results
		var i int
		if i = findQSlot([]byte(qname), results.qsubs); i < 0 {
			i = len(results.qsubs)
			nqsub := make([]*subscription, 0, len(qr))
			results.qsubs = append(results.qsubs, nqsub)
		}
		for _, sub := range qr {
			if isRemoteQSub(sub) {
				ns := atomic.LoadInt32(&sub.qw)
				// Shadow these subscriptions
				for n := 0; n < int(ns); n++ {
					results.qsubs[i] = append(results.qsubs[i], sub)
				}
			} else {
				results.qsubs[i] = append(results.qsubs[i], sub)
			}
		}
	}
}
859482
func (r *Result) Add(other *Result) {
	r.Succeeded += other.Succeeded
	r.Skipped += other.Skipped
	r.Failed += other.Failed
	r.Panicked += other.Panicked
	r.FixturePanicked += other.FixturePanicked
	r.ExpectedFailures += other.ExpectedFailures
	r.Missed += other.Missed
	if r.WorkDir != "" && other.WorkDir != "" {
		r.WorkDir += ":" + other.WorkDir
	} else if other.WorkDir != "" {
		r.WorkDir = other.WorkDir
	}
}
959423
func (result *Result) AppendResult(src *Result) {
	if src.RowsAffected == 0 && len(src.Fields) == 0 {
		return
	}
	if result.Fields == nil {
		result.Fields = src.Fields
	}
	result.RowsAffected += src.RowsAffected
	if src.InsertID != 0 {
		result.InsertID = src.InsertID
	}
	if len(result.Rows) == 0 {
		// we haven't gotten any result yet, just save the new extras.
		result.Extras = src.Extras
	} else {
		// Merge the EventTokens / Fresher flags within Extras.
		if src.Extras == nil {
			// We didn't get any from innerq. Have to clear any
			// we'd have gotten already.
			if result.Extras != nil {
				result.Extras.EventToken = nil
				result.Extras.Fresher = false
			}
		} else {
			// We may have gotten an EventToken from
			// innerqr.  If we also got one earlier, merge
			// it. If we didn't get one earlier, we
			// discard the new one.
			if result.Extras != nil {
				// Note if any of the two is nil, we get nil.
				result.Extras.EventToken = EventTokenMinimum(result.Extras.EventToken, src.Extras.EventToken)

				result.Extras.Fresher = result.Extras.Fresher && src.Extras.Fresher
			}
		}
	}
	result.Rows = append(result.Rows, src.Rows...)
}
97523
func (s *Simulation) AddNodesAndConnectFull(count int, opts ...AddNodeOption) (ids []enode.ID, err error) {
	if count < 2 {
		return nil, errors.New("count of nodes must be at least 2")
	}
	ids, err = s.AddNodes(count, opts...)
	if err != nil {
		return nil, err
	}
	err = s.Net.ConnectNodesFull(ids)
	if err != nil {
		return nil, err
	}
	return ids, nil
}
472747
func (n *Node) AddToEdge(to *Node, v int64, residual, inline bool) {
	n.AddToEdgeDiv(to, 0, v, residual, inline)
}
1166755
func (n *node) insert(item Item, maxItems int) Item {
	i, found := n.items.find(item)
	if found {
		out := n.items[i]
		n.items[i] = item
		return out
	}
	if len(n.children) == 0 {
		n.items.insertAt(i, item)
		return nil
	}
	if n.maybeSplitChild(i, maxItems) {
		inTree := n.items[i]
		switch {
		case item.Less(inTree):
			// no change, we want first split node
		case inTree.Less(item):
			i++ // we want second split node
		default:
			out := n.items[i]
			n.items[i] = item
			return out
		}
	}
	return n.mutableChild(i).insert(item, maxItems)
}
1181815
func (s *Selection) AddSelection(sel *Selection) *Selection {
	if sel == nil {
		return s.AddNodes()
	}
	return s.AddNodes(sel.Nodes...)
}
570712
func (p *pathTree) add(rel string) {
	if !p.caseSensitive {
		rel = strings.ToLower(rel)
	}
	p.leafs.Add(rel)
	parentDirs(rel, func(par string) bool {
		p.nodes.Add(par)
		return true
	})
}
180504
func (g Graph) NodesByKind(nodeKinds ...string) []graph.Node {
	ret := []graph.Node{}

	kinds := sets.NewString(nodeKinds...)
	for _, node := range g.internal.Nodes() {
		if kinds.Has(g.Kind(node)) {
			ret = append(ret, node)
		}
	}

	return ret
}
1111120
func (tn *TreeNode) processResult(client curator.CuratorFramework, evt curator.CuratorEvent) error {
	tn.tree.logger.Debugf("ProcessResult: %v", evt)
	newStat := evt.Stat()
	switch evt.Type() {
	case curator.EXISTS:
		if tn.parent != nil {
			tn.tree.handleException(errors.New("unexpected EXISTS on non-root node"))
		}
		if evt.Err() == nil {
			tn.state.CompareAndSwap(NodeStateDEAD, NodeStatePENDING)
			tn.wasCreated()
		}
	case curator.CHILDREN:
		switch evt.Err() {
		case zk.ErrNoNode:
			tn.wasDeleted()
		case nil:
			tn.Lock()
			oldChildData := tn.childData
			if oldChildData != nil && oldChildData.Stat().Mzxid == newStat.Mzxid {
				// Only update stat if mzxid is same, otherwise we might obscure
				// GET_DATA event updates.
				tn.childData.SetStat(newStat)
			}
			tn.Unlock()

			if len(evt.Children()) == 0 {
				break
			}
			// Present new children in sorted order for test determinism.
			children := sort.StringSlice(evt.Children())
			sort.Sort(children)
			for _, child := range children {
				if accepted := tn.tree.selector.AcceptChild(path.Join(tn.path, child)); !accepted {
					continue
				}
				tn.Lock()
				if _, exists := tn.children[child]; !exists {
					fullPath := path.Join(tn.path, child)
					node := NewTreeNode(tn.tree, fullPath, tn)
					tn.children[child] = node
					node.wasCreated()
				}
				tn.Unlock()
			}
		}
	case curator.GET_DATA:
		switch evt.Err() {
		case zk.ErrNoNode:
			tn.wasDeleted()
		case nil:
			newChildData := NewChildData(evt.Path(), newStat, evt.Data())
			oldChildData := tn.ChildData()
			if tn.tree.cacheData {
				tn.SwapChildData(newChildData)
			} else {
				tn.SwapChildData(NewChildData(evt.Path(), newStat, nil))
			}

			var added bool
			if tn.parent == nil {
				// We're the singleton root.
				added = tn.state.Swap(NodeStateLIVE) != NodeStateLIVE
			} else {
				added = tn.state.CompareAndSwap(NodeStatePENDING, NodeStateLIVE)
				if !added {
					// Ordinary nodes are not allowed to transition from dead -> live;
					// make sure this isn't a delayed response that came in after death.
					if tn.state.Load() != NodeStateLIVE {
						return nil
					}
				}
			}

			if added {
				tn.tree.publishEvent(TreeCacheEventNodeAdded, newChildData)
			} else {
				if oldChildData == nil || oldChildData.Stat().Mzxid != newStat.Mzxid {
					tn.tree.publishEvent(TreeCacheEventNodeUpdated, newChildData)
				}
			}
		default:
			tn.tree.logger.Printf("Unknown GET_DATA event[%v]: %s", evt.Path(), evt.Err())
		}
	default:
		// An unknown event, probably an error of some sort like connection loss.
		tn.tree.logger.Printf("Unknown event: %v", evt)
		// Don't produce an initialized event on error; reconnect can fix this.
		atomic.AddUint64(&tn.tree.outstandingOps, ^uint64(0))

		return nil
	}

	// Decrease by 1
	if atomic.AddUint64(&tn.tree.outstandingOps, ^uint64(0)) == 0 {
		if !tn.tree.isInitialized.IsSet() {
			tn.tree.isInitialized.Set()
			tn.tree.publishEvent(TreeCacheEventInitialized, nil)
		}
	}
	return nil
}
1159622
func (c *keyValueChanger) Add(k string, v interface{}) error {
	if c.err != nil {
		return c.err
	}
	_, err := c.node.addChild(keyValue{k, v})
	return err
}
148870
func (r *results) merge(other *results) {
	if other == nil {
		return
	}

	r.mu.Lock()
	defer r.mu.Unlock()

	r.rowsAffected += other.rowsAffected
	if other.lastInsertID > r.lastInsertID {
		r.lastInsertID = other.lastInsertID
	}
	r.cumulativeDuration += other.duration
}
165141
func (s *Selection) AppendNodes(ns ...*html.Node) *Selection {
	return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) {
		sn.AppendChild(n)
	})
}
1177406
func (irt *immutableRangeTree) Add(entries ...Entry) *immutableRangeTree {
	if len(entries) == 0 {
		return irt
	}

	cache := newCache(irt.dimensions)
	top := make(orderedNodes, len(irt.top))
	copy(top, irt.top)
	added := uint64(0)
	for _, entry := range entries {
		irt.add(&top, cache, entry, &added)
	}

	tree := newImmutableRangeTree(irt.dimensions)
	tree.top = top
	tree.number = irt.number + added
	return tree
}
865382
func (xmlNode *XmlNode) AddChild(data interface{}) (err error) {
	switch t := data.(type) {
	default:
		if nodes, err := xmlNode.coerce(data); err == nil {
			for _, node := range nodes {
				if err = xmlNode.addChild(node); err != nil {
					break
				}
			}
		}
	case *DocumentFragment:
		if nodes, err := xmlNode.coerce(data); err == nil {
			for _, node := range nodes {
				if err = xmlNode.addChild(node); err != nil {
					break
				}
			}
		}
	case Node:
		err = xmlNode.addChild(t)
	}
	return
}
17243
func (extr *ContentExtractor) nodesToCheck(doc *goquery.Document) []*goquery.Selection {
	var output []*goquery.Selection
	tags := []string{"p", "pre", "td"}
	for _, tag := range tags {
		selections := doc.Children().Find(tag)
		if selections != nil {
			selections.Each(func(i int, s *goquery.Selection) {
				output = append(output, s)
			})
		}
	}
	return output
}
85683
func (n *node) put(key Key, value interface{}) bool {
	if key.IsEmpty() {
		return n.setValue(value)
	}
	child, changed := n.findChild(key[0], true)
	remainingKey := key[1:]
	return child.put(remainingKey, value) || changed
}