lib/collection: introduce init `HashMap::from`
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 24 Oct 2015 18:02:31 +0000 (14:02 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 19 Dec 2015 08:40:58 +0000 (03:40 -0500)
HashSet has one, why not HashMap?

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/core/collection/hash_collection.nit

index ac4a8a1..926a1d9 100644 (file)
@@ -265,6 +265,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
+               recover_with(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