HashTable.opIndexAssign

Inserts a new value at key or reassigns the element if key already exists in the hash table.

struct HashTable(Key, Value, alias hasher = hash)
ref
Value
opIndexAssign
()
(
auto ref Value value
,
auto ref Key key
)
if (
isHashFunction!(hasher, Key)
)

Parameters

key Key

The key to insert the value at.

value Value

The value to be inserted.

Return Value

Type: Value

Just inserted element.

Examples

HashTable!(string, int) hashTable;
assert("Pachycephalosaurus" !in hashTable);

hashTable["Pachycephalosaurus"] = 6;
assert(hashTable.length == 1);
assert("Pachycephalosaurus" in hashTable);

hashTable["Pachycephalosaurus"] = 6;
assert(hashTable.length == 1);
assert("Pachycephalosaurus" in hashTable);

Meta