# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
-# Introduce Hashmap and Hashset.
+# Introduce `HashMap` and `HashSet`.
module hash_collection
import array
+redef class Map[K, V]
+ # Get a `HashMap[K, V]` as default implementation
+ new do return new HashMap[K, V]
+end
+
# A HashCollection is an array of HashNode[K] indexed by the K hash value
private abstract class HashCollection[K]
type N: HashNode[K]
end
end
+ redef fun get_or_null(key)
+ do
+ var c = node_at(key)
+ if c == null then
+ return null
+ else
+ return c._value
+ end
+ end
+
redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
redef fun length do return _the_length
enlarge(0)
end
- redef var keys: RemovableCollection[K] = new HashMapKeys[K, V](self)
- redef var values: RemovableCollection[V] = new HashMapValues[K, V](self)
+ redef var keys: RemovableCollection[K] = new HashMapKeys[K, V](self) is lazy
+ redef var values: RemovableCollection[V] = new HashMapValues[K, V](self) is lazy
+ redef fun has_key(k) do return node_at(k) != null
end
# View of the keys of a HashMap
# A `Set` implemented with a hash table.
# Keys of such a map cannot be null and require a working `hash` method
-class HashSet[E: Object]
+class HashSet[E]
super Set[E]
super HashCollection[E]
redef fun new_set do return new HashSet[E]
end
-private class HashSetNode[E: Object]
+private class HashSetNode[E]
super HashNode[E]
redef type N: HashSetNode[E]
end
-private class HashSetIterator[E: Object]
+private class HashSetIterator[E]
super Iterator[E]
redef fun is_ok do return _node != null