// addAt will add the provided node at the provided index.  Returns
// a node if one was overwritten.
198808
func (nodes *orderedNodes) addAt(i int, node *node) *node {
	if i == len(*nodes) {
		*nodes = append(*nodes, node)
		return nil
	}

	if (*nodes)[i].value == node.value {
		overwritten := (*nodes)[i]
		// this is a duplicate, there can't be a duplicate
		// point in the last dimension
		(*nodes)[i] = node
		return overwritten
	}

	*nodes = append(*nodes, nil)
	copy((*nodes)[i+1:], (*nodes)[i:])
	(*nodes)[i] = node
	return nil
}
365284
func (c *Chain) AddNode(nodes ...Node) {
	if c == nil {
		return
	}
	for _, node := range nodes {
		c.nodeGroups = append(c.nodeGroups, NewNodeGroup(node))
	}
}
1337579
func (s *CloudFormationStackRecord) SetCreatedAt(v time.Time) *CloudFormationStackRecord {
	s.CreatedAt = &v
	return s
}
933755
func (t *FST) addNode(nodeIn *UnCompiledNode) (int64, error) {
	// fmt.Printf("FST.addNode pos=%v numArcs=%v\n", t.bytes.position(), nodeIn.NumArcs)
	if nodeIn.NumArcs == 0 {
		if nodeIn.IsFinal {
			return FST_FINAL_END_NODE, nil
		}
		return FST_NON_FINAL_END_NODE, nil
	}

	startAddress := t.bytes.position()
	// fmt.Printf("  startAddr=%v\n", startAddress)

	doFixedArray := t.shouldExpand(nodeIn)
	if doFixedArray {
		// fmt.Println("  fixedArray")
		if len(t.bytesPerArc) < nodeIn.NumArcs {
			t.bytesPerArc = make([]int, util.Oversize(nodeIn.NumArcs, 1))
		}
	}

	t.arcCount += int64(nodeIn.NumArcs)

	lastArc := nodeIn.NumArcs - 1

	lastArcStart := t.bytes.position()
	maxBytesPerArc := 0
	for arcIdx := 0; arcIdx < nodeIn.NumArcs; arcIdx++ {
		arc := nodeIn.Arcs[arcIdx]
		target := arc.Target.(*CompiledNode)
		flags := byte(0)
		// fmt.Printf("  arc %v label=%v -> target=%v\n", arcIdx, arc.label, target.node)

		if arcIdx == lastArc {
			flags += FST_BIT_LAST_ARC
		}

		if t.lastFrozenNode == target.node && !doFixedArray {
			flags += FST_BIT_TARGET_NEXT
		}

		if arc.isFinal {
			flags += FST_BIT_FINAL_ARC
			if arc.nextFinalOutput != NO_OUTPUT {
				flags += FST_BIT_ARC_HAS_FINAL_OUTPUT
			}
		} else {
			assert(arc.nextFinalOutput == NO_OUTPUT)
		}

		targetHasArcs := target.node > 0

		if !targetHasArcs {
			flags += FST_BIT_STOP_NODE
		} else if t.inCounts != nil {
			panic("not implemented yet")
		}

		if arc.output != NO_OUTPUT {
			flags += FST_BIT_ARC_HAS_OUTPUT
		}

		t.bytes.WriteByte(flags)
		var err error
		if err = t.writeLabel(t.bytes, arc.label); err != nil {
			return 0, err
		}

		// fmt.Printf("  write arc: label=%c flags=%v target=%v pos=%v output=%v\n",
		// 	rune(arc.label), flags, target.node, t.bytes.position(),
		// 	t.outputs.outputToString(arc.output))

		if arc.output != NO_OUTPUT {
			if err = t.outputs.Write(arc.output, t.bytes); err != nil {
				return 0, err
			}
			// fmt.Println("    write output")
			t.arcWithOutputCount++
		}

		if arc.nextFinalOutput != NO_OUTPUT {
			// fmt.Println("    write final output")
			if err = t.outputs.writeFinalOutput(arc.nextFinalOutput, t.bytes); err != nil {
				return 0, err
			}
		}

		if targetHasArcs && (flags&FST_BIT_TARGET_NEXT) == 0 {
			assert(target.node > 0)
			// fmt.Println("    write target")
			if err = t.bytes.WriteVLong(target.node); err != nil {
				return 0, err
			}
		}

		// just write the arcs "like normal" on first pass, but record
		// how many bytes each one took, and max byte size:
		if doFixedArray {
			t.bytesPerArc[arcIdx] = int(t.bytes.position() - lastArcStart)
			lastArcStart = t.bytes.position()
			if t.bytesPerArc[arcIdx] > maxBytesPerArc {
				maxBytesPerArc = t.bytesPerArc[arcIdx]
			}
		}
	}

	if doFixedArray {
		MAX_HEADER_SIZE := 11 // header(byte) + numArcs(vint) + numBytes(vint)
		assert(maxBytesPerArc > 0)
		// 2nd pass just "expands" all arcs to take up a fixed byte size
		// create the header
		header := make([]byte, MAX_HEADER_SIZE)
		bad := store.NewByteArrayDataOutput(header)
		// write a "false" first arc:
		bad.WriteByte(FST_ARCS_AS_FIXED_ARRAY)
		bad.WriteVInt(int32(nodeIn.NumArcs))
		bad.WriteVInt(int32(maxBytesPerArc))
		headerLen := bad.Position()

		fixedArrayStart := startAddress + int64(headerLen)

		// expand the arcs in place, backwards
		srcPos := t.bytes.position()
		destPos := fixedArrayStart + int64(nodeIn.NumArcs)*int64(maxBytesPerArc)
		assert(destPos >= srcPos)
		if destPos > srcPos {
			t.bytes.skipBytes(int(destPos - srcPos))
			for arcIdx := nodeIn.NumArcs - 1; arcIdx >= 0; arcIdx-- {
				destPos -= int64(maxBytesPerArc)
				srcPos -= int64(t.bytesPerArc[arcIdx])
				if srcPos != destPos {
					assert2(destPos > srcPos,
						"destPos=%v srcPos=%v arcIdx=%v maxBytesPerArc=%v bytesPerArc[arcIdx]=%v nodeIn.numArcs=%v",
						destPos, srcPos, arcIdx, maxBytesPerArc, t.bytesPerArc[arcIdx], nodeIn.NumArcs)
					t.bytes.copyBytesInside(srcPos, destPos, t.bytesPerArc[arcIdx])
				}
			}
		}

		// now write the header
		t.bytes.writeBytesAt(startAddress, header[:headerLen])
	}

	thisNodeAddress := t.bytes.position() - 1

	t.bytes.reverse(startAddress, thisNodeAddress)

	// PackedInts uses int as the index, so we cannot handle > 2.1B
	// nodes when packing:
	assert2(t.nodeAddress == nil || t.nodeCount < math.MaxInt32,
		"cannot create a packed FST with more than 2.1 billion nodes")

	t.nodeCount++
	var node int64
	if t.nodeAddress != nil {
		panic("not implemented yet")
	} else {
		node = thisNodeAddress
	}
	t.lastFrozenNode = node

	// fmt.Printf("  ret node=%v address=%v nodeAddress=%v",
	// 	node, thisNodeAddress, t.nodeAddress)
	return node, nil
}
566510
func (ot *orderedTree) add(entry Entry) *node {
	var node *node
	list := &ot.top

	for i := uint64(1); i <= ot.dimensions; i++ {
		if isLastDimension(ot.dimensions, i) {
			overwritten := list.add(
				newNode(entry.ValueAtDimension(i), entry, false),
			)
			if overwritten == nil {
				ot.number++
			}
			return overwritten
		}
		node, _ = list.getOrAdd(entry, i, ot.dimensions)
		list = &node.orderedNodes
	}

	return nil
}
34498
func (e *IndexEntry) AppendTo(b []byte) []byte {
	if len(b) < indexEntrySize {
		if cap(b) < indexEntrySize {
			b = make([]byte, indexEntrySize)
		} else {
			b = b[:indexEntrySize]
		}
	}

	binary.BigEndian.PutUint64(b[:8], uint64(e.MinTime))
	binary.BigEndian.PutUint64(b[8:16], uint64(e.MaxTime))
	binary.BigEndian.PutUint64(b[16:24], uint64(e.Offset))
	binary.BigEndian.PutUint32(b[24:28], uint32(e.Size))

	return b
}
185200
func AddrSubscribeAt(ns netns.NsHandle, ch chan<- AddrUpdate, done <-chan struct{}) error {
	return addrSubscribeAt(ns, netns.None(), ch, done, nil, false)
}
1008339
func (g *Graph) DeleteAt(i int) {
	if i < 0 || i >= g.Len() {
		return
	}
	if i < (g.Len() - 1) {
		g.Out = append(g.Out[:i], g.Out[i+1:]...)
	} else {
		g.Out = g.Out[:i]
	}
}
1203982
func (c *Cluster) AddNode(n *Node) error {
	if n == nil {
		return ErrClusterNodeMustBeNonNil
	}
	c.Lock()
	defer c.Unlock()
	for _, node := range c.nodes {
		if n == node {
			return nil
		}
	}
	if c.isCurrentState(clusterRunning) {
		if err := n.start(); err != nil {
			return err
		}
	}
	c.nodes = append(c.nodes, n)
	return nil
}
119266
func (cons *SimpleConsumer) AddHealthCheckAt(path string, callback thealthcheck.CallbackFunc) {
	thealthcheck.AddEndpoint("/"+cons.GetID()+path, callback)
}
319528
func (t *Tab) addNodes(node *gcdapi.DOMNode) {
	t.debugf("addNode id: %d\n", node.NodeId)
	t.debugf("%#v\n", node)
	newEle := t.nodeToElement(node)

	t.eleMutex.Lock()
	t.elements[newEle.id] = newEle
	t.eleMutex.Unlock()
	//log.Printf("Added new element: %s\n", newEle)
	t.requestChildNodes(newEle.id, 1)
	if node.Children != nil {
		// add child nodes
		for _, v := range node.Children {
			t.addNodes(v)
		}
	}
	if node.ContentDocument != nil {
		t.addNodes(node.ContentDocument)
	}
	t.lastNodeChangeTimeVal.Store(time.Now())
}
901775
func (set StringSet) Add(i string) bool {
	_, found := set[i]
	set[i] = struct{}{}
	return !found //False if it e  xisted already
}
614158
func (lir *LookupInResult) ContentAt(idx int, valuePtr interface{}) error {
	if idx > len(lir.contents) {
		return errors.New("the supplied index was invalid")
	}
	return lir.contents[idx].as(valuePtr, JSONDecode)
}
1014645
func (router *SimpleRouter) AddHealthCheckAt(path string, callback thealthcheck.CallbackFunc) {
	thealthcheck.AddEndpoint("/"+router.GetID()+path, callback)
}
844574
func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder {
	b.stmts = append(b.stmts, stmt)
	b.names = append(b.names, names...)
	return b
}
1145805
func (rs *ResultSet) StringAt(index int) (string, error) {
	value, err := rs.ValueAt(index)
	if err != nil {
		return "", err
	}
	return value.String(), nil
}
946156
func (p *Path) InsertAt(index int, point *Point) *Path {
	(&p.PointSet).InsertAt(index, point)
	return p
}