// Add adds the passed nonce to the map and handles eviction of the oldest item
// if adding the new item would exceed the max limit.  Adding an existing item
// makes it the most recently used item.
//
// This function is safe for concurrent access.
966082
func (m *mruNonceMap) Add(nonce uint64) {
	m.mtx.Lock()
	defer m.mtx.Unlock()

	// When the limit is zero, nothing can be added to the map, so just
	// return.
	if m.limit == 0 {
		return
	}

	// When the entry already exists move it to the front of the list
	// thereby marking it most recently used.
	if node, exists := m.nonceMap[nonce]; exists {
		m.nonceList.MoveToFront(node)
		return
	}

	// Evict the least recently used entry (back of the list) if the the new
	// entry would exceed the size limit for the map.  Also reuse the list
	// node so a new one doesn't have to be allocated.
	if uint(len(m.nonceMap))+1 > m.limit {
		node := m.nonceList.Back()
		lru := node.Value.(uint64)

		// Evict least recently used item.
		delete(m.nonceMap, lru)

		// Reuse the list node of the item that was just evicted for the
		// new item.
		node.Value = nonce
		m.nonceList.MoveToFront(node)
		m.nonceMap[nonce] = node
		return
	}

	// The limit hasn't been reached yet, so just add the new item.
	node := m.nonceList.PushFront(nonce)
	m.nonceMap[nonce] = node
}
1230821
func (a Annotation) Add(key, value string) Annotation {
	a.setVal(key, value)
	return a
}
606837
func (c *baseCatcher) Add(err error) {
	if err == nil {
		return
	}

	c.mutex.Lock()
	defer c.mutex.Unlock()

	c.errs = append(c.errs, err)
}
1251282
func (c *Cache) Add(index uint64, obj interface{}) bool {
	return c.getShard(index).add(index, obj)
}
745214
func (b Builder) Add(elems ...int) {
	if b.done {
		return
	}
	for _, elem := range elems {
		b.result.elems[elem] = struct{}{}
	}
}
582524
func (m *clientConnMap) Add(dest string) error {
	// If the connection already exists, just exit early
	if _, ok := m.Get(dest); ok {
		return nil
	}

	conn, err := grpc.Dial(dest, m.options...)

	m.Lock()
	_, ok := m.conns[dest]
	if !ok && err == nil {
		m.conns[dest] = conn
	}
	m.Unlock()

	if ok && err == nil {
		_ = conn.Close()
	}

	return err
}
751013
func (s *Stack) Add(m ...Middleware) {
	for _, mdw := range m {
		s.Stack = s.Stack.Append(alice.Constructor(mdw))
	}
}
494463
func (b *Builder) Add(args ...string) error {
	for _, a := range args {
		if err := b.add(a); err != nil {
			return errwrap.Wrapf(fmt.Sprintf("invalid key/value pair %q: {{err}}", a), err)
		}
	}

	return nil
}
750714
func (r *RecordList) Add(ev EventBuilder, fn Listener) int {
	idx, rec := r.Find(ev.Name())
	if idx == -1 {
		rec := &record{ev: ev, name: ev.Name()}
		rec.setList([]unsafe.Pointer{unsafe.Pointer(&fn)})
		r.append(rec)
		return 1
	}

	oldList := rec.getUnsafeList()
	newCount := len(oldList) - rec.inactiveItems + 1
	if rec.inactiveItems == 0 {
		rec.inactiveItems = len(oldList)
		newList := make([]unsafe.Pointer, len(oldList)*2+1)
		// copy so that the new list items are at the end of the list,
		// this lets the slot search later run and find free space faster.
		copy(newList[len(oldList)+1:], oldList)
		newList[len(oldList)] = unsafe.Pointer(&fn)
		rec.setList(newList)
		return newCount
	}

	for i, ptr := range oldList {
		if ptr == nil {
			rec.storeAtIndex(i, fn)
			rec.inactiveItems--
			return newCount
		}
	}

	panic("unreachable")
}
797038
func (a *accounter) Add(n int64) int64 {
	return atomic.AddInt64(&a.current, n)
}
1111545
func (table *RegommendTable) Add(key interface{}, data map[interface{}]float64) *RegommendItem {
	item := CreateRegommendItem(key, data)

	// Add item to engine.
	table.Lock()
	table.items[key] = &item

	// engine values so we don't keep blocking the mutex.
	addedItem := table.addedItem
	table.Unlock()

	// Trigger callback after adding an item to engine.
	if addedItem != nil {
		addedItem(&item)
	}

	return &item
}
1030068
func (c *Context) Add(key string, value interface{}) {
	c.data[key] = value
}
556060
func (c *ExpirationCache) Add(obj interface{}) error {
	key, err := c.keyFunc(obj)
	if err != nil {
		return KeyError{obj, err}
	}
	c.cacheStorage.Add(key, &timestampedEntry{obj, c.clock.Now()})
	return nil
}
451659
func (b *Base) Add(key string, value interface{}) Serializer {
	return b.AddIf(alwaysTrue, key, value)
}
1250801
func (s *SyncedSet) Add(datas ...interface{}) {
	s.Lock()
	defer s.Unlock()
	for _, data := range datas {
		s.set[data] = true
	}
}
544068
func (i *Item) addItem(property string, value *Item) {
	i.Properties[property] = append(i.Properties[property], value)
}
1199516
func (m *NormMap) add(l int64) bool {
	assert(m.size <= 256) // once we add > 256 values, we nullify the map in addNumericField and don't use this strategy
	if l >= math.MinInt8 && l <= math.MaxInt8 {
		index := int(l + 128)
		if previous := m.singleByteRange[index]; previous < 0 {
			m.singleByteRange[index] = int16(m.size)
			m.size++
			return true
		}
		return false
	}
	if _, ok := m.other[l]; !ok {
		m.other[l] = int16(m.size)
		m.size++
		return true
	}
	return false
}