HashTable.insert

Inserts a new element in the hash table.

If the element with the same key was already in the table, it reassigns it with the new value, but $(D_PSYMBOL insert) returns 0. Otherwise 1 is returned.

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

Parameters

keyValue KeyValue

Key/value pair.

Return Value

Type: size_t

The number of the inserted elements with a unique key.

Examples

HashTable!(string, int) hashTable;

assert(hashTable.insert(hashTable.KeyValue("number", 1)) == 1);
assert(hashTable["number"] == 1);
assert(hashTable.insert(hashTable.KeyValue("number", 2)) == 0);
assert(hashTable["number"] == 2);

Meta