HashTable.insert

Inserts a forward range of key/value pairs into the hash table.

If some of the elements in the range have the same key, they are reassigned but are not counted as inserted elements. So the value returned by this function will be less than the range length.

  1. size_t insert(KeyValue keyValue)
  2. size_t insert(KeyValue keyValue)
  3. size_t insert(R range)
    struct HashTable(Key, Value, alias hasher = hash)
    size_t
    insert
    (
    R
    )
    (
    scope R range
    )
    if (
    isHashFunction!(hasher, Key)
    )

Parameters

R

Range type.

range R

Forward range.

Return Value

Type: size_t

The number of the inserted elements with a unique key.

Examples

HashTable!(string, int) hashTable;

hashTable.KeyValue[2] range = [
    hashTable.KeyValue("one", 1),
    hashTable.KeyValue("two", 2),
];

assert(hashTable.insert(range[]) == 2);
assert(hashTable["one"] == 1);
assert(hashTable["two"] == 2);

Meta