Map
implemented with a hash table.var map = new HashMap[nullable String, Int]
map[null] = 0
map["one"] = 1
map["two"] = 2
assert map[null] == 0
assert map["one"] == 1
assert map.keys.has("two")
assert map.values.length == 3
core :: HashMap :: defaultinit
core $ HashMap :: get_or_null
Get the item atkey
or null if key
is not in the map.
core :: HashCollection :: _array
core :: HashCollection :: _capacity
core :: HashCollection :: _first_item
core :: HashCollection :: _last_accessed_key
The last key accessed (used for cache)core :: HashCollection :: _last_accessed_node
The last node accessed (used for cache)core :: HashCollection :: _last_item
core :: HashCollection :: _the_length
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: 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 :: HashCollection :: array
core :: HashCollection :: array=
core :: HashCollection :: capacity
core :: HashCollection :: capacity=
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Map :: defaultinit
core :: MapRead :: defaultinit
core :: HashMap :: defaultinit
core :: HashCollection :: defaultinit
core :: Object :: defaultinit
core :: MapRead :: filter_keys
Return all elements ofkeys
that have a value.
core :: HashCollection :: first_item
core :: HashCollection :: first_item=
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 :: HashCollection :: gt_collide
Count and update length of collisions fornode_at_idx
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 :: HashCollection :: last_accessed_key
The last key accessed (used for cache)core :: HashCollection :: last_accessed_key=
The last key accessed (used for cache)core :: HashCollection :: last_accessed_node
The last node accessed (used for cache)core :: HashCollection :: last_accessed_node=
The last node accessed (used for cache)core :: HashCollection :: last_item
core :: HashCollection :: last_item=
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 :: native_class_name
The class name of the object in CString format.core :: HashCollection :: node_at_idx
Return the node associated with the key (but with the index already known)core :: 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
core :: HashCollection :: remove_node
Remove the node assosiated with the keyserialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
core :: HashCollection :: st_collide
Count and update length of collisions forstore
core :: HashCollection :: the_length
core :: HashCollection :: the_length=
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
.
Serializer::serialize
dot :: AttributeMap
Map of graph/node/edge attribute that can be rendered to dot.more_collections :: DefaultMap
A map with a default value.nitc :: FlowHashMap
A FlowSet based on a HashMap.more_collections :: MultiHashMap
Simple way to store anHashMap[K, Array[V]]
ShaderVariable
instances by their name
serialization :: StrictHashMap
Maps instances to a value, usesis_same_serialized
and serialization_hash
.
# A `Map` implemented with a hash table.
#
# ~~~
# var map = new HashMap[nullable String, Int]
# map[null] = 0
# map["one"] = 1
# map["two"] = 2
#
# assert map[null] == 0
# assert map["one"] == 1
# assert map.keys.has("two")
# assert map.values.length == 3
# ~~~
class HashMap[K, V]
super Map[K, V]
super HashCollection[K]
redef type N: HashMapNode[K, V] is fixed
redef fun [](key)
do
var c = node_at(key)
if c == null then
return provide_default_value(key)
else
return c._value
end
end
redef fun get_or_null(key)
do
var c = node_at(key)
if c == null then
return null
else
return c._value
end
end
redef fun iterator do return new HashMapIterator[K,V](self)
redef fun length do return _the_length
redef fun is_empty do return _the_length == 0
redef fun []=(key, v)
do
if _capacity == 0 then enlarge(17) # 17 because magic in `store`
var i = index_at(key)
var c = node_at_idx(i, key)
if c != null then
c._key = key
c._value = v
else
store(i, new HashMapNode[K, V](key, v))
end
end
redef fun clear do raz
init
do
_capacity = 0
_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
end
lib/core/collection/hash_collection.nit:207,1--282,3