core :: Map :: defaultinit
# Maps are associative collections: `key` -> `item`.
#
# The main operator over maps is [].
#
# var map: Map[String, Int] = new ArrayMap[String, Int]
# # ...
# map["one"] = 1 # Associate 'one' to '1'
# map["two"] = 2 # Associate 'two' to '2'
# assert map["one"] == 1
# assert map["two"] == 2
#
# Instances of maps can be used with the for structure
#
# for key, value in map do
# assert (key == "one" and value == 1) or (key == "two" and value == 2)
# end
#
# The keys and values in the map can also be manipulated directly with the `keys` and `values` methods.
#
# assert map.keys.has("one") == true
# assert map.keys.has("tree") == false
# assert map.values.has(1) == true
# assert map.values.has(3) == false
#
interface Map[K, V]
super MapRead[K, V]
# Set the `value` at `key`.
#
# Values can then get retrieved with `[]`.
#
# var x = new HashMap[String, Int]
# x["four"] = 4
# assert x["four"] == 4
#
# If the key was associated with a value, this old value is discarded
# and replaced with the new one.
#
# x["four"] = 40
# assert x["four"] == 40
# assert x.values.has(4) == false
#
fun []=(key: K, value: V) is abstract
# Add each (key,value) of `map` into `self`.
# If a same key exists in `map` and `self`, then the value in self is discarded.
#
# var x = new HashMap[String, Int]
# x["four"] = 4
# x["five"] = 5
# var y = new HashMap[String, Int]
# y["four"] = 40
# y["nine"] = 90
# x.add_all y
# assert x["four"] == 40
# assert x["five"] == 5
# assert x["nine"] == 90
fun add_all(map: MapRead[K, V])
do
var i = map.iterator
while i.is_ok do
self[i.key] = i.item
i.next
end
end
# Alias for `add_all`
fun recover_with(map: MapRead[K, V]) is deprecated do add_all(map)
# Remove all items
#
# var x = new HashMap[String, Int]
# x["four"] = 4
# x.clear
# assert x.keys.has("four") == false
#
# ENSURE `is_empty`
fun clear is abstract
redef fun values: RemovableCollection[V] is abstract
redef fun keys: RemovableCollection[K] is abstract
end
lib/core/collection/abstract_collection.nit:684,1--766,3