var _capacity: Int = 0 # Size of _array
var _length: Int = 0 # Number of items in the map
- readable var _first_item: nullable N = null # First added item (used to visit items in nice order)
+ var _first_item: nullable N = null # First added item (used to visit items in nice order)
var _last_item: nullable N = null # Last added item (same)
# The last key accessed (used for cache)
# Then store it in the array
var next = new_array[index]
new_array[index] = node
+ node._prev_in_bucklet = null
node._next_in_bucklet = next
if next != null then next._prev_in_bucklet = node
node = node._next_item
private abstract class HashNode[K: Object]
var _key: K
type N: HashNode[K]
- readable writable var _next_item: nullable N = null
- readable writable var _prev_item: nullable N = null
+ var _next_item: nullable N = null
+ var _prev_item: nullable N = null
var _prev_in_bucklet: nullable N = null
var _next_in_bucklet: nullable N = null
init(k: K)
do
var c = node_at(key)
if c == null then
- abort
+ return provide_default_value(key)
else
return c._value
end
enlarge(0)
end
- redef var keys: HashMapKeys[K, V] = new HashMapKeys[K, V](self)
- redef var values: HashMapValues[K, V] = new HashMapValues[K, V](self)
+ redef var keys: RemovableCollection[K] = new HashMapKeys[K, V](self)
+ redef var values: RemovableCollection[V] = new HashMapValues[K, V](self)
end
# View of the keys of a HashMap
-class HashMapKeys[K: Object, V]
+private class HashMapKeys[K: Object, V]
super RemovableCollection[K]
# The original map
var map: HashMap[K, V]
end
# View of the values of a Map
-class HashMapValues[K: Object, V]
+private class HashMapValues[K: Object, V]
super RemovableCollection[V]
# The original map
var map: HashMap[K, V]
init(map: HashMap[K, V])
do
_map = map
- _node = map.first_item
+ _node = map._first_item
end
end
end
end
-class HashSetIterator[E: Object]
+private class HashSetIterator[E: Object]
super Iterator[E]
redef fun is_ok do return _node != null