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 util • default equivalence !> equivalence with hash[key type])
private void copy on write()
if !state • writable
state = state • copy()
assert state • writable
implement void clear()
implement value type or null put(key type key, value type value)
state • reserve(size + 1)
hash : equivalence • hash(key)
index : state • bucket index(hash)
var entry : state • the buckets[index]
if entry is null
state • the buckets[index] = hash cell[key type, value type] • new(key, hash, value)
state • size += 1
return missing • instance
loop
if hash == entry • the key hash && equivalence(key, entry • key)
old value : entry • value
entry • set value(value)
return old value
next : entry • next
if next is null
entry • next = hash cell[key type, value type] • new(key, hash, value)
state • size += 1
return missing • instance
else
entry = next
implement value type or null remove(key type key)
hash : equivalence • hash(key)
index : state • bucket index(hash)
var entry : state • the buckets[index]
if entry is null
return missing • instance
if hash == entry • the key hash && equivalence(key, entry • key)
old value : entry • value
state • the buckets[index] = entry • next
new size : state • size - 1
assert new size is nonnegative
state • size = new size
return old value
loop
next entry : entry • next
if next entry is null
return missing • instance
if hash == next entry • the key hash && equivalence(key, next entry • key)
old value : next entry • value
entry • next = next entry • next
new size : state • size - 1
assert new size is nonnegative
state • size = new size
return old value
entry = next entry