Map

MapEntry: key, value

Map: Map, take, insert, set, remove, clear, reserve, all, any, none, size, capacity, resize, operator[], contains, empty, loadFactor, iterator

MapIterator: MapIterator, hasValue, value, increment

struct MapEntry<Key: Hashable, Value>

A key-value pair stored in a map.

key

Key key;

The entry's key.

value

Value value;

The entry's value.

struct Map<Key: Hashable, Value>

A hash map from keys to values.

Map

Map()

Initializes an empty map

take

Map<Key, Value> take()

Moves the map out, leaving an empty map in its place.

insert

void insert(Key key, Value value)

Inserts an element into the map. The key must not already be in the map.

set

void set(Key key, Value value)

Inserts, or updates an existing value.

remove

Value? remove(Key& e)

Removes an element from the map, returning its value, or null if it isn't there.

clear

void clear()

Removes all entries from the map, keeping the allocated buckets.

reserve

void reserve(int minimumCapacity)

Ensures that the bucket count is at least the given number.

all

bool all<Pred: bool(MapEntry<Key, Value>&)>(Pred predicate)

Returns true if all entries satisfy the predicate.

bool all<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if all entries satisfy the predicate.

any

bool any<Pred: bool(MapEntry<Key, Value>&)>(Pred predicate)

Returns true if any entry satisfies the predicate.

bool any<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if any entry satisfies the predicate.

none

bool none<Pred: bool(MapEntry<Key, Value>&)>(Pred predicate)

Returns true if no entry satisfies the predicate.

bool none<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if no entry satisfies the predicate.

size

int size()

Returns the number of entries.

capacity

int capacity()

Returns the number of buckets.

resize

void resize()

Resizes the map. This includes copying the old table into a new, bigger one

operator[]

Value&? operator[](Key& e)

Returns the value for the given key, or null.

contains

bool contains(Key& e)

Checks if e is part of the map.

empty

bool empty()

Returns true if the map has no entries.

loadFactor

float64 loadFactor()

Returns the load factor for the map. This is used to increase the map size once the load factor gets too big.

iterator

MapIterator<Key, Value> iterator()

Iterate over the map

struct MapIterator<Key, Value>: Iterator<MapEntry<Key, Value>&>

Iterates over the entries of a map.

MapIterator

MapIterator(Map<Key, Value>& map)

Initializes an iterator over the given map.

hasValue

bool hasValue()

Returns true if there are more entries.

value

MapEntry<Key, Value>& value()

Returns the current entry.

increment

void increment()

Advances to the next entry.