v
to the array associated with k
.If there is no array associated, then create it.
For the inverse operation, see remove_one
.
var m = new MultiHashMap[String, Char]
m.add_one("four", 'i')
m.add_one("four", 'i')
m.add_one("four", 'i')
m.add_one("four", 'i')
assert m.has_key("four")
assert m["four"] == ['i', 'i', 'i', 'i']
# Add `v` to the array associated with `k`.
#
# If there is no array associated, then create it.
#
# For the inverse operation, see `remove_one`.
#
# ```
# var m = new MultiHashMap[String, Char]
# m.add_one("four", 'i')
# m.add_one("four", 'i')
# m.add_one("four", 'i')
# m.add_one("four", 'i')
# assert m.has_key("four")
# assert m["four"] == ['i', 'i', 'i', 'i']
# ```
fun add_one(k: K, v: V)
do
var x = self.get_or_null(k)
if x != null then
x.add(v)
else
self[k] = [v]
end
end
lib/more_collections/more_collections.nit:38,2--61,4