core :: ArrayMap :: defaultinit
core $ ArrayMap :: couple_iterator
Return a new iteralot on all couplesserialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: CoupleMap :: couple_iterator
Return a new iteralot on all couplescore :: Map :: defaultinit
core :: Cloneable :: defaultinit
core :: MapRead :: defaultinit
core :: CoupleMap :: defaultinit
core :: Object :: defaultinit
core :: ArrayMap :: defaultinit
core :: MapRead :: filter_keys
Return all elements ofkeys
that have a value.
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: MapRead :: get_or_default
Get the item atkey
or return default
if not in map
core :: MapRead :: get_or_null
Get the item atkey
or null if key
is not in the map.
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: MapRead :: keys_sorted_by_values
Return an array of all keys sorted with their values usingcomparator
.
core :: MapRead :: lookup_all_values
Search all the values inpe.greaters
.
core :: MapRead :: lookup_values
Combine the values inpe.greaters
from the most smaller elements that have a value.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).core :: MapRead :: provide_default_value
Called by the underling implementation of[]
to provide a default value when a key
has no value
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
core :: MapRead :: to_map_comparator
A comparator that compares things with their values in self.serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: MapRead :: values_sorted_by_key
Return an array of all values sorted with their keys usingcomparator
.
# Associative arrays implemented with an array of (key, value) pairs.
class ArrayMap[K, E]
super CoupleMap[K, E]
super Cloneable
# O(n)
redef fun [](key)
do
var i = index(key)
if i >= 0 then
return _items[i].second
else
return provide_default_value(key)
end
end
# O(n)
redef fun []=(key, item)
do
var i = index(key)
if i >= 0 then
_items[i].second = item
else
_items.push(new Couple[K,E](key, item))
end
end
redef var keys: RemovableCollection[K] = new ArrayMapKeys[K, E](self) is lazy
redef var values: RemovableCollection[E] = new ArrayMapValues[K, E](self) is lazy
# O(1)
redef fun length do return _items.length
redef fun couple_iterator do return _items.iterator
redef fun is_empty do return _items.is_empty
redef fun clear do _items.clear
# Assume the capacity to be at least `cap`.
fun enlarge(cap: Int) do _items.enlarge(cap)
redef fun couple_at(key)
do
var i = index(key)
if i >= 0 then
return _items[i]
else
return null
end
end
# Internal storage.
private var items = new Array[Couple[K,E]]
# fast remove the ith element of the array
private fun remove_at_index(i: Int)
do
_items[i] = _items.last
_items.pop
end
# The last positive result given by a index(1) call
private var last_index: Int = 0
# Where is the `key` in `_item`?
# return -1 if not found
private fun index(key: K): Int
do
var l = _last_index
if l < _items.length and _items[l].first == key then return l
var i = 0
while i < _items.length do
if _items[i].first == key then
_last_index = i
return i
end
i += 1
end
return -1
end
# Shallow clone of `self`
#
# ~~~
# var a = new ArrayMap[String,Int]
# a["one"] = 1
# a["two"] = 2
# var b = a.clone
# assert a == b
# a["zero"] = 0
# assert a != b
# ~~~
#
# Note that the clone is shallow and keys and values are shared between `self` and the result.
#
# ~~~
# var aa = new ArrayMap[String, Array[Int]]
# aa["two"] = [1,2]
# var bb = aa.clone
# assert aa == bb
# aa["two"].add 5
# assert aa == bb
# ~~~
redef fun clone
do
var res = new ArrayMap[K,E]
res.add_all self
return res
end
end
lib/core/collection/array.nit:689,1--800,3