core: fix typos in union_find
[nit.git] / lib / core / collection / hash_collection.nit
index 7c9fc6a..25cf2b9 100644 (file)
@@ -20,6 +20,11 @@ redef class Map[K, V]
        new do return new HashMap[K, V]
 end
 
+redef class Set[E]
+       # Get an instance of `HashSet[E]`, the default implementation
+       new do return new HashSet[E]
+end
+
 # A HashCollection is an array of HashNode[K] indexed by the K hash value
 private abstract class HashCollection[K]
        type N: HashNode[K]
@@ -165,7 +170,6 @@ private abstract class HashCollection[K]
        # Force a capacity
        fun enlarge(cap: Int)
        do
-               var old_cap = _capacity
                # get a new capacity
                if cap < _the_length + 1 then cap = _the_length + 1
                if cap <= _capacity then return
@@ -176,16 +180,6 @@ private abstract class HashCollection[K]
                var new_array = new NativeArray[nullable N](cap)
                _array = new_array
 
-               # clean the new array
-               var i = cap - 1
-               while i >=0 do
-                       new_array[i] = null
-                       i -= 1
-               end
-
-               if _the_length == 0 then return
-               if _capacity <= old_cap then return
-
                # Reput items in the array
                var node = _first_item
                while node != null do
@@ -249,7 +243,7 @@ class HashMap[K, V]
                end
        end
 
-       redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
+       redef fun iterator do return new HashMapIterator[K,V](self)
 
        redef fun length do return _the_length
 
@@ -276,6 +270,12 @@ class HashMap[K, V]
                _the_length = 0
        end
 
+       # Build a list filled with the items of `coll`.
+       init from(coll: Map[K, V]) do
+               init
+               add_all(coll)
+       end
+
        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