Mutable dictionary backed by a hashtable.
public class hash set[readonly value element type]
extends base hash set[element type]
implements set[element type]
public overload hash set(equivalence with hash[element type] equivalence)
super(equivalence)
public overload hash set()
super(runtime utildefault equivalence !> any value !> equivalence with hash[element type])
private void copy on write()
if !statewritable
state = statecopy()
assert statewritable
implement void clear()
implement void add(element type the value)
statereserve(size + 1)
do add(the value)
implement void add all(readonly collection[element type] the collection)
statereserve(size + the collectionsize)
for (the element : the collectionelements)
do add(the element)
private void do add(element type the value)
hash : equivalencehash(the value)
index : statebucket index(hash)
var entry : statethe buckets[index]
if entry is null
statethe buckets[index] = hash cell[element type] • new(the value, hash)
statesize += 1
return
loop
if hash == entrythe hash && equivalence(the value, entrythe value)
return
next : entrynext
if next is null
entrynext = hash cell[element type] • new(the value, hash)
statesize += 1
return
else
entry = next
implement boolean remove(element type the element)
hash : equivalencehash(the element)
index : statebucket index(hash)
var entry : statethe buckets[index]
if entry is null
return false
if hash == entrythe hash && equivalence(the element, entrythe value)
statethe buckets[index] = entrynext
return true
loop
next : entrynext
if next is null
return false
if hash == nextthe hash && equivalence(the element, nextthe value)
entrynext = nextnext
return true
entry = next
private void decrement size()
new size : statesize - 1
assert new size is nonnegative
statesize = new size