insert new key / value into AVL tree
@param tree
@param key
@param value
@returns {*}
767358
function add(tree, key, value) {
  if (!tree) {
    return create(key, value)
  }

  switch (compare(tree.key, key)) {
    case -1:
      tree.left = add(tree.left, key, value)
      return balance(tree) == -2 ? add_left(tree, key) : patch(tree)
    case 1:
      tree.right = add(tree.right, key, value)
      return balance(tree) == 2 ? add_right(tree, key) : patch(tree)
    case 0:
      tree.value = value
      break
    default:
      break
  }

  return tree
}
777995
@Nullable
  public synchronized V put(K key, V value) {
    // We do remove and insert instead of just replace, in order to cause a structural change
    // to the map, as we always want the latest inserted element to be last in the queue.
    V oldValue = mMap.remove(key);
    mSizeInBytes -= getValueSizeInBytes(oldValue);
    mMap.put(key, value);
    mSizeInBytes += getValueSizeInBytes(value);
    return oldValue;
  }
155156
public void add(Object key, Object value) {
        Object existing = mMap.get(key);
        if (existing instanceof List) {
            if (value instanceof List) {
                ((List)existing).addAll((List)value);
            }
            else {
                ((List)existing).add(value);
            }
        }
        else if (existing == null && !mMap.containsKey(key)) {
            if (value instanceof List) {
                mMap.put(key, new ArrayList((List)value));
            }
            else {
                mMap.put(key, value);
            }
        }
        else {
            List list = new ArrayList();
            list.add(existing);
            if (value instanceof List) {
                list.addAll((List)value);
            }
            else {
                list.add(value);
            }
            mMap.put(key, list);
        }
    }
736216
@Override
    public V put(String key, V value) {
        // Keys can not be null
        if (key == null) {
            throw new NullPointerException("Key can not be null");
        }

        // Empty keys are stored in the root
        if (key.equals("")) {
            PatriciaNode<V> node = new PatriciaNode<>(key, value, -1);
            node.setValue(value);
            root.setRight(node);
            entries++;
            return value;
        }

        // Find nearest node
        PatriciaNode<V> nearest = findNearestNode(key);

        // Key already exist, replace value and return
        if (key.equals(nearest.getKey())) {
            nearest.setValue(value);
            return value;
        }

        // Find differing bit and create new node to insert
        int bit = findFirstDifferingBit(key, nearest.getKey());
        PatriciaNode<V> node = new PatriciaNode<>(key, value, bit);

        // Insert new node
        insertNode(node);

        entries++;

        return value;
    }
1205422
public void add(K key, V value)
  {
    if (key == null) {
      return;
    }

    K []keys = _keys;
    final int size = _size;
    
    for (int i = size - 1; i >= 0; i--) {
      if (key.equals(keys[i])) {
        _values[i].add(value);
        return;
      }
    }

    if (! ensureCapacity(size)) {
      return;
    }
    
    _keys[size] = key;
    _values[size] = new ArrayList<V>();
    _values[size].add(value);
    
    _size = size + 1;
  }
1216238
function put(key, value) {
  const entry = { key, value };
  // Note: No protection agains replacing, and thus orphan entries. By design.
  this._keymap[key] = entry;
  if (this.tail) {
    // link previous tail to the new tail (entry)
    this.tail.newer = entry;
    entry.older = this.tail;
  } else {
    // we're first in -- yay
    this.head = entry;
  }
  // add new entry to the end of the linked list -- it's now the freshest entry.
  this.tail = entry;
  if (this.size === this.limit) {
    // we hit the limit -- remove the head
    return this.shift();
  }
  // increase the size counter
  this.size += 1;
  return undefined;
}
452492
public static void insertOrCreate(String key, String keyword, String nature, int freq) {
		Forest dic = get(key);
		if(dic==null){
			dic = new Forest() ;
			put(key,key,dic);
		}
		String[] paramers = new String[2];
		paramers[0] = nature;
		paramers[1] = String.valueOf(freq);
		Value value = new Value(keyword, paramers);
		Library.insertWord(dic, value);
	}
1138132
def insert(self, index, value):
        ''''''
        newnode = LookupTreeNode(index, value)
        level = 0
        node = self.root
        while True:
            ind = _getbits(newnode.index, level)
            level += 1
            child = node.children[ind]
            if child is None or child.index == newnode.index:
                if child:
                    assert child.value == newnode.value
                node.children[ind] = newnode
                break
            elif child.index == _root_index:
                # This is a branch
                node = child
            else:
                branch = LookupTreeNode()
                nind = _getbits(newnode.index, level)
                cind = _getbits(child.index, level)
                node.children[ind] = branch

                # Life gets tricky when...
                if nind == cind:
                    branch.children[cind] = child
                    # recurse
                    node = branch
                else:
                    branch.children[nind] = newnode
                    branch.children[cind] = child
                    break
230460
public static void insert(String key, Value value) {
        Forest forest = get(key);
        Library.insertWord(forest, value);
    }
641886
function (tree, prefix) {
  prefix = prefix || '';
  var result = {};

  _.each(tree, function (val, key) {
    if (_.isObject(val))
      _.extend(result, treeToPaths(val, prefix + key + '.'));
    else
      result[prefix + key] = val;
  });

  return result;
}
1355165
public static void addValue(String key, Object value, MultiValueMap<String, String> params) {
        if (value != null) {
            params.add(key, value.toString());
        }
    }
603060
public PersistentHashArrayMappedTrie<K,V> put(K key, V value) {
    if (root == null) {
      return new PersistentHashArrayMappedTrie<>(new Leaf<>(key, value));
    } else {
      return new PersistentHashArrayMappedTrie<>(root.put(key, value, key.hashCode(), 0));
    }
  }
510357
function(key, value){
                            var json = null;
                            try { json = JSON.parse(value); } catch (e){} //try get json
                            if (json === null) json = $scope.utils.tryGetFunction(value) || json; //try get function

                            /* add element to the object */
                            if ($scope.node.type() === 'object') {
                                if (json !== null){
                                    $scope.json[key] = json
                                } else {
                                    $scope.json[key] = value
                                }

                            }
                            /* add element(s) to the array */
                            else if ($scope.node.type() === 'array') {
                                if (json !== null) {
                                    if (json.constructor === Array){
                                        /* push new array elements to the array */
                                        $scope.json.push.apply($scope.json, json);
                                    } else {
                                        /* push single element to the array */
                                        $scope.json.push(json);
                                    }
                                } else {
                                    $scope.json.push(value);
                                }
                            }
                            $scope.refresh();
                        }
95865
public void append(int key, long value) {
        if (mSize != 0 && key <= mKeys[mSize - 1]) {
            put(key, value);
            return;
        }

        int pos = mSize;
        if (pos >= mKeys.length) {
            growKeyAndValueArrays(pos + 1);
        }

        mKeys[pos] = key;
        mValues[pos] = value;
        mSize = pos + 1;
    }
247971
@SuppressWarnings("unchecked")
    public V put(final int key, final V value) {
        checkNotNull(value, "Value cannot be null");
        V oldValue = null;
        int index = intHash(key, mask);
        while (null != values[index]) {
            if (key == keys[index]) {
                oldValue = (V) values[index];
                break;
            }
            index = ++index & mask;
        }
        if (null == oldValue) {
            ++size;
            keys[index] = key;
        }
        values[index] = value;
        if (size > resizeThreshold) {
            increaseCapacity();
        }
        return oldValue;
    }
1108181
def insert(index, value)
      node = self
      cidx = nil

      # Traverse the tree to find the right node to add or replace the value.
      while node do
        # All nodes that we find on the way that are full will be split into
        # two half-full nodes.
        if node.size >= @tree.node_size
          # Re-add the index from the last parent node since we will descent
          # into one of the split nodes.
          index += node.parent.offsets[cidx] if node.parent
          node = node.split_node
        end

        # Once we have reached a leaf node we can insert or replace the value.
        if node.is_leaf?
          node.values.insert(index, value)
          node.parent.adjust_offsets(node, 1) if node.parent
          return
        else
          # Descend into the right child node to add the value to.
          cidx = node.search_child_index(index)
          if (index -= node.offsets[cidx]) < 0
            node.fatal "Index (#{index}) became negative"
          end
          node = node.children[cidx]
        end
      end

      node.fatal "Could not find proper node to insert the value while " +
        "looking for index #{index}"
    end
642029
function treeSetMutable (address, tree, value) {
  if (address.length === 0) {
    return value
  } else {
    const [ rest, last ] = tail(address)
    const parent = treeGet(rest, tree)
    if (checkType(NODE, parent)) {
      parent.children[last] = value
    } else {
      parent[last] = value
    }
    return tree
  }
}