// Constructs a node from reader's data, and adds it. Doesn't pin.
774036
func (adder *Adder) add(reader io.Reader) (ipld.Node, error) {
	chnk, err := chunker.FromString(reader, adder.Chunker)
	if err != nil {
		return nil, err
	}

	params := ihelper.DagBuilderParams{
		Dagserv:    adder.bufferedDS,
		RawLeaves:  adder.RawLeaves,
		Maxlinks:   ihelper.DefaultLinksPerBlock,
		NoCopy:     adder.NoCopy,
		CidBuilder: adder.CidBuilder,
	}

	db, err := params.New(chnk)
	if err != nil {
		return nil, err
	}
	var nd ipld.Node
	if adder.Trickle {
		nd, err = trickle.Layout(db)
	} else {
		nd, err = balanced.Layout(db)
	}
	if err != nil {
		return nil, err
	}

	return nd, adder.bufferedDS.Commit()
}
123365
func (i *Input) Add(src io.Reader) error {
	i.Mutex.Lock()
	defer i.Mutex.Unlock()
	if i.src != nil {
		return fmt.Errorf("Maximum number of sources reached: 1")
	}
	i.src = src
	return nil
}
511749
func (n *node) addChild(key string, data interface{}, order int) int {
	// find the first occurrence of a param token
	p0, p1 := -1, -1
	for i := 0; i < len(key); i++ {
		if p0 < 0 && key[i] == '<' {
			p0 = i
		}
		if p0 >= 0 && key[i] == '>' {
			p1 = i
			break
		}
	}

	if p0 > 0 && p1 > 0 || p1 < 0 {
		// param token occurs after a static string, or no param token: create a static node
		child := &node{
			static:    true,
			key:       key,
			minOrder:  order,
			children:  make([]*node, 256),
			pchildren: make([]*node, 0),
			pindex:    n.pindex,
			pnames:    n.pnames,
		}
		n.children[key[0]] = child
		if p1 > 0 {
			// param token occurs after a static string
			child.key = key[:p0]
			n = child
		} else {
			// no param token: done adding the child
			child.data = data
			child.order = order
			return child.pindex + 1
		}
	}

	// add param node
	child := &node{
		static:    false,
		key:       key[p0 : p1+1],
		minOrder:  order,
		children:  make([]*node, 256),
		pchildren: make([]*node, 0),
		pindex:    n.pindex,
		pnames:    n.pnames,
	}
	pattern := ""
	pname := key[p0+1 : p1]
	for i := p0 + 1; i < p1; i++ {
		if key[i] == ':' {
			pname = key[p0+1 : i]
			pattern = key[i+1 : p1]
			break
		}
	}
	if pattern != "" {
		// the param token contains a regular expression
		child.regex = regexp.MustCompile("^" + pattern)
	}
	pnames := make([]string, len(n.pnames)+1)
	copy(pnames, n.pnames)
	pnames[len(n.pnames)] = pname
	child.pnames = pnames
	child.pindex = len(pnames) - 1
	n.pchildren = append(n.pchildren, child)

	if p1 == len(key)-1 {
		// the param token is at the end of the key
		child.data = data
		child.order = order
		return child.pindex + 1
	}

	// process the rest of the key
	return child.addChild(key[p1+1:], data, order)
}
596598
func (n *NodeStore) Put(key []byte, data []byte) error {
	return n.store.Put(n.addr, key, data)
}
527580
func ToTree(rdr io.Reader) (*Node, error) {
	// We need to put an *os.File reader in a ByteReader or the xml.NewDecoder
	// will wrap it in a bufio.Reader and seek on the file beyond where the
	// xml.Decoder parses!
	if _, ok := rdr.(io.ByteReader); !ok {
		rdr = myByteReader(rdr) // see code at EOF
	}

	p := xml.NewDecoder(rdr)
	p.CharsetReader = X2jCharsetReader
	n, perr := xmlToTree("", nil, p)
	if perr != nil {
		return nil, perr
	}

	return n, nil
}
222342
func (s *Server) AddNode(c context.Context, e *pb.Node) (*pb.RingStatus, error) {
	s.Lock()
	defer s.Unlock()
	s.ctxlog.Debug("Got AddNode request")
	b, err := s.getBuilderFn(fmt.Sprintf("%s/%s.builder", s.cfg.RingDir, s.servicename))
	if err != nil {
		s.ctxlog.WithFields(log.Fields{
			"path": fmt.Sprintf("%s/%s.builder", s.cfg.RingDir, s.servicename),
			"err":  err,
		}).Warning("Unable to load builder for change")
		return &pb.RingStatus{}, err
	}
	n, err := b.AddNode(e.Active, e.Capacity, e.Tiers, e.Addresses, e.Meta, e.Conf)
	if err != nil {
		return &pb.RingStatus{}, err
	}
	s.ctxlog.WithFields(log.Fields{
		"ID":        n.ID(),
		"Active":    n.Active(),
		"Capacity":  n.Capacity(),
		"Tiers":     strings.Join(n.Tiers(), "|"),
		"Addresses": strings.Join(n.Addresses(), "|"),
		"Meta":      n.Meta(),
		"Config":    n.Config(),
	}).Debug("proposed ring entry")
	newRing := b.Ring()
	s.ctxlog.WithField("proposed-ringver", newRing.Version()).Info("attempting to apply ring version")
	err = s.applyRingChange(&RingChange{b: b, r: newRing, v: newRing.Version()})
	if err != nil {
		s.ctxlog.WithFields(log.Fields{
			"proposed-ringver": newRing.Version(),
			"ringver":          s.r.Version(),
			"err":              err,
		}).Warning("failed to apply ring change")
		return &pb.RingStatus{Status: false, Version: s.r.Version()}, err
	}
	s.ctxlog.WithField("ringver", s.r.Version()).Info("updated ring")
	return &pb.RingStatus{Status: true, Version: s.r.Version()}, nil
}
858689
func (p *Pipeline) Add(n Acceptor) {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	p.nodes = append(p.nodes, n)
}
999826
func addNode(tree huffmanTree, path int, path_len int, value int) huffmanTree {
	root := tree
	for path_len > 1 {
		if tree.IsLeaf() {
			_panicf("Trying to add node to leaf")
		}

		// get the current bit
		path_len--
		one := path & 1
		path = path >> 1

		// add node / leaf
		if one == 1 {
			if tree.Right() != nil {
				tree = tree.Right()
			} else {
				tree.(*huffmanNode).right = &huffmanNode{0, 0, nil, nil}
				tree = tree.Right()
			}
		} else {
			if tree.Left() != nil {
				tree = tree.Left()
			} else {
				tree.(*huffmanNode).left = &huffmanNode{0, 0, nil, nil}
				tree = tree.Left()
			}
		}
	}

	// set value
	one := path & 1
	path = path >> 1

	if one == 1 {
		tree.(*huffmanNode).right = huffmanLeaf{0, value}
	} else {
		tree.(*huffmanNode).left = huffmanLeaf{0, value}
	}

	return root
}
48621
func (mc MongoClient) AddReading(r contract.Reading) (string, error) {
	s := mc.getSessionCopy()
	defer s.Close()

	var mapped models.Reading
	id, err := mapped.FromContract(r)
	if err != nil {
		return "", err
	}

	mapped.TimestampForAdd()

	err = s.DB(mc.database.Name).C(db.ReadingsCollection).Insert(&mapped)
	if err != nil {
		return "", errorMap(err)
	}
	return id, err
}
15796
func (n *node) read(p *page) {
	n.pgid = p.id
	n.isLeaf = ((p.flags & leafPageFlag) != 0)
	n.inodes = make(inodes, int(p.count))

	for i := 0; i < int(p.count); i++ {
		inode := &n.inodes[i]
		if n.isLeaf {
			elem := p.leafPageElement(uint16(i))
			inode.flags = elem.flags
			inode.key = elem.key()
			inode.value = elem.value()
		} else {
			elem := p.branchPageElement(uint16(i))
			inode.pgid = elem.pgid
			inode.key = elem.key()
		}
		_assert(len(inode.key) > 0, "read: zero-length inode key")
	}

	// Save first key so we can find the node in the parent when we spill.
	if len(n.inodes) > 0 {
		n.key = n.inodes[0].key
		_assert(len(n.key) > 0, "read: zero-length node key")
	} else {
		n.key = nil
	}
}
1087981
func putLinkNode(nodeMetaBucket *bbolt.Bucket, l *LinkNode) error {
	// First serialize the LinkNode into its raw-bytes encoding.
	var b bytes.Buffer
	if err := serializeLinkNode(&b, l); err != nil {
		return err
	}

	// Finally insert the link-node into the node metadata bucket keyed
	// according to the its pubkey serialized in compressed form.
	nodePub := l.IdentityPub.SerializeCompressed()
	return nodeMetaBucket.Put(nodePub, b.Bytes())
}
82496
func pushNode(list []*node, n *node, max int) ([]*node, *node) {
	if len(list) < max {
		list = append(list, nil)
	}
	removed := list[len(list)-1]
	copy(list[1:], list)
	list[0] = n
	return list, removed
}
488556
func (c *cluster) addNode(node *Node) error {
	// If the node being added is the coordinator, set it for this node.
	if node.IsCoordinator {
		c.Coordinator = node.ID
	}

	// add to cluster
	if !c.addNodeBasicSorted(node) {
		return nil
	}

	// add to topology
	if c.Topology == nil {
		return fmt.Errorf("Cluster.Topology is nil")
	}
	if !c.Topology.addID(node.ID) {
		return nil
	}
	c.Topology.nodeStates[node.ID] = node.State

	// save topology
	return c.saveTopology()
}
169043
func (d *dir) add(n node) {
	if d.children == nil {
		d.children = make(map[string]node)
	}

	d.children[n.name()] = n
	d.mod = time.Now()
}
1301209
func (c *Client) AddNode(host string, command AddNodeCommand) error {
	return c.AddNodeAsync(host, command).Receive()
}
545959
func (p *parser) addChild(n *Node) {
	if p.shouldFosterParent() {
		p.fosterParent(n)
	} else {
		p.top().AppendChild(n)
	}

	if n.Type == ElementNode {
		p.oe = append(p.oe, n)
	}
}
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
}