lib/map: make concrete `Map.keys` and `Map.values` lazy
[nit.git] / lib / standard / collection / hash_collection.nit
index f385729..e5ff507 100644 (file)
@@ -235,6 +235,16 @@ class HashMap[K, V]
                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
@@ -262,8 +272,9 @@ class HashMap[K, V]
                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
@@ -408,7 +419,7 @@ end
 
 # 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]
 
@@ -462,12 +473,12 @@ class HashSet[E: Object]
        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