Function HashTable.opIndexAssign

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

ref Value opIndexAssign (
  auto ref Value value,
  auto ref Key key
);

Parameters

NameDescription
key The key to insert the value at.
value The value to be inserted.

Returns

Just inserted element.

Example

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);