Base class for the dictionary backed by a linked list.
public abstract class base hash dictionary[readonly value key type, value value type]
implements readonly dictionary[key type, value type]
namespace parameters
default size : 16
protected class hash cell[readonly value key type, value value type]
implements dictionary • entry[key type, value type]
protected integer the key hash
private var value type the value
public overload hash cell(key type the key, integer the key hash, value type the value, hash cell[key type, value type] or null next)
this • the key = the key
this • the key hash = the key hash
this • the value = the value
this • next = next
Wrapper of an array that implements on-demand resizing and copy-on-write semantics.
The same dictionary_state can be shared by multiple instances of base_hash_dictionarys.
protected class dictionary state[readonly value key type, value value type]
import ideal • machine • elements • array
Specifies whether this instance of dictionary_state is writable.
A single non-writable copy can be shared among multiple instances of base_hash_dictionary.
var boolean writable
Specifies how many elements are stored in this dictionary_state.
The size is less or equal to the_buckets.size.
var nonnegative size
Construct a dictionary state with an array of specified size.
overload dictionary state(nonnegative initial size)
size = 0
Construct a dictionary state with a table of default size.
overload dictionary state()
this(parameters • default size)
Make sure the array is of at least the specified size.
void reserve(nonnegative reserve size)
if the buckets • size >= reserve size
if new size < reserve size
for var nonnegative i : 0; i < old buckets • size; i += 1
return
new size = reserve size
old buckets • scrub(0, old buckets • size)
protected dictionary state[key type, value type] copy()
for var nonnegative i : 0; i < the buckets • size; i += 1
while bucket is_not null
new cell : hash cell[key type, value type] • new(bucket • key, bucket • the key hash, bucket • value, result • the buckets[i])
return result
protected overload base hash dictionary(equivalence with hash[key type] equivalence)
this • equivalence = equivalence
protected overload base hash dictionary(equivalence with hash[key type] equivalence, dictionary state[key type, value type] state)
this • equivalence = equivalence
this • state = state
Specifies whether the collection has more than zero elements.
Shortcut for !is_empty.
implement boolean is not empty => state • size != 0
Enumerates elements in some collection-defined order.
This method returns a snapshot of the collection state, so subsequent mutations
of the collection do not cause changes in the returned list.
implement immutable list[dictionary • entry[key type, value type]] elements()
if is empty
for var nonnegative i : 0; i < state • the buckets • size; i += 1
return result • frozen copy()
implement value type or null get(key type key)
implement boolean contains key(key type key)
implement immutable set[key type] keys()
if is empty
pass
for var nonnegative i : 0; i < state • the buckets • size; i += 1
return result • frozen copy()
implement readonly collection[value type] values()
for var nonnegative i : 0; i < state • the buckets • size; i += 1
return result • frozen copy()
private string debug display()
for var nonnegative i : 0; i < state • the buckets • size; i += 1
s = s ++ "b" ++ i ++ ": "
for var entry : state • the buckets[i]; entry is_not null; entry = entry • next
s = s ++ "\n"
return s