package core.map
Map :: struct (Key_Type: type_expr, Value_Type: type_expr)
where ValidKey(Key_Type)
{
allocator: Allocator
hashes: [] i32
entries: [..] Entry(Key_Type, Value_Type)
}
Map is a generic hash-map implementation that uses chaining. Values can be of any type. Keys must of a type that supports the core.hash.hash, and the '==' operator.
Map.as_iter :: (m: &Map) -> #auto
Produces an iterator that yields all values of the map, in an unspecified order, as Map is unordered.
Map.clear :: (map: &Map) -> void
Removes all entries from the hash map. Does NOT modify memory, so be wary of dangling pointers!
Map.copy :: (oldMap: &Map, allocator: ? Allocator) -> Map(oldMap.Key_Type, oldMap.Value_Type)
Map.copy :: (oldMap: Map, allocator: ? Allocator) -> Map(oldMap.Key_Type, oldMap.Value_Type)
Map.format_map :: (output: &conv.Format_Output, format: &conv.Format, x: &Map($K, $V)) -> void
Helper procedure to nicely format a Map when printing. Rarely ever called directly, instead used by conv.format_any.
Map.get :: (map: &Map, key: map.Key_Type) -> ? map.Value_Type
Returns the value at the specified key, or .None
if the value is not present
Map.get_opt :: (map: &Map, key: map.Key_Type) -> ? map.Value_Type
DEPRECATED - Use map.get
instead.
Returns an Optional of the value at the specified key. The Optional has a value if the key is present, otherwise the optional does not have a value.
Map.get_ptr :: (map: &Map, key: map.Key_Type) -> &map.Value_Type
Returns a pointer to the value at the specified key, or null if the key is not present.
Map.get_ptr_or_create :: (map: &Map, key: map.Key_Type) -> &map.Value_Type
Returns a pointer to the value at the specified key. If the key is not in the map, a new value is created and inserted, then the pointer to that value is returned.
Map.literal :: ($Key: type_expr, $Value: type_expr, values: [] MapLiteralValue(Key, Value)) -> #auto
Quickly create a Map with some entries.
Map.literal(str, i32, .[
.{ "test", 123 },
.{ "foo", 456 },
]);
Map.make :: macro ($Key: type_expr, $Value: type_expr, allocator) -> Map(Key, Value)
Allows for creation of a Map using make().
m := make(Map(str, i32));
Creates and initializes a new map using the types provided.
Map.put :: (map: &Map, key: map.Key_Type, value: map.Value_Type) -> void
Sets the value at the specified key, or creates a new entry if the key was not already present.
Map.update :: macro (map: &Map, key: map.Key_Type, body: Code) -> void
Helper macro that finds a value by the key, and if it exists, runs the code, providing an it
variable that is a pointer to the value.
m: Map(str, i32);
m->update("test") {
*it += 10;
}
or:
m->update("test", [v](*v += 10));