Mutable dictionary backed by a hashtable.
public class hash dictionary[readonly value key type, value value type]
extends base hash dictionary[key type, value type]
implements dictionary[key type, value type]
public overload hash dictionary(equivalence with hash[key type] equivalence)
super(equivalence)
public overload hash dictionary()
super(runtime utildefault equivalence !> equivalence with hash[key type])
private void copy on write()
if !statewritable
state = statecopy()
assert statewritable
implement void clear()
implement value type or null put(key type key, value type value)
statereserve(size + 1)
hash : equivalencehash(key)
index : statebucket index(hash)
var entry : statethe buckets[index]
if entry is null
statethe buckets[index] = hash cell[key type, value type] • new(key, hash, value)
statesize += 1
return missinginstance
loop
if hash == entrythe key hash && equivalence(key, entrykey)
old value : entryvalue
entryset value(value)
return old value
next : entrynext
if next is null
entrynext = hash cell[key type, value type] • new(key, hash, value)
statesize += 1
return missinginstance
else
entry = next
implement value type or null remove(key type key)
hash : equivalencehash(key)
index : statebucket index(hash)
var entry : statethe buckets[index]
if entry is null
return missinginstance
if hash == entrythe key hash && equivalence(key, entrykey)
old value : entryvalue
statethe buckets[index] = entrynext
new size : statesize - 1
assert new size is nonnegative
statesize = new size
return old value
loop
next entry : entrynext
if next entry is null
return missinginstance
if hash == next entrythe key hash && equivalence(key, next entrykey)
old value : next entryvalue
entrynext = next entrynext
new size : statesize - 1
assert new size is nonnegative
statesize = new size
return old value
entry = next entry