end
# A HashCollection is an array of HashNode[K] indexed by the K hash value
-private class HashCollection[K: Object, N: HashNode[K], E: Object]
+private class HashCollection[K: Object, N: HashNode[K], E]
special Collection[E]
-special ArrayCapable[N]
- attr _array: NativeArray[N] # Used to store items
- attr _capacity: Int # Size of _array
- redef readable attr _length: Int # Number of items in the map
+special ArrayCapable[nullable N]
+ attr _array: nullable NativeArray[nullable N] = null # Used to store items
+ attr _capacity: Int = 0 # Size of _array
+ redef readable attr _length: Int = 0 # Number of items in the map
- readable attr _first_item: N # First added item (used to visit items in nice order)
- attr _last_item: N # Last added item (same)
+ readable attr _first_item: nullable N = null # First added item (used to visit items in nice order)
+ attr _last_item: nullable N = null # Last added item (same)
# The last index accessed
- attr _last_accessed_index: Int
+ attr _last_accessed_index: Int = -1
# The last key accessed
- attr _last_accessed_key: K
+ attr _last_accessed_key: nullable K = null
# Return the index of the k element
meth index_at(k: K): Int
do
var arr = _array
- assert k != null
# Fisrt step: look in the last indexed elt
if k == _last_accessed_key then return _last_accessed_index
private class HashNode[K]
meth key: K is abstract
type N: HashNode[K]
- readable writable attr _next_item: N
- readable writable attr _prev_item: N
+ readable writable attr _next_item: nullable N = null
+ readable writable attr _prev_item: nullable N = null
end
class HashMap[K, V]
redef meth key do return first
redef type N: HashMapNode[K, V]
- redef init(k: K, v: V)
+ init(k: K, v: V)
do
first = k
second = v
return _node.second
end
- redef meth item=(value)
- do
- assert is_ok
- _node.second = value
- end
+ #redef meth item=(value)
+ #do
+ # assert is_ok
+ # _node.second = value
+ #end
redef meth key
do
attr _map: HashMap[K, V]
# The current node
- attr _node: HashMapNode[K, V]
+ attr _node: nullable HashMapNode[K, V]
init(map: HashMap[K, V])
do
attr _set: HashSet[E]
# The position in the internal map storage
- attr _node: HashSetNode[E]
+ attr _node: nullable HashSetNode[E]
init(set: HashSet[E])
do