HashMap_AB

A manually managed hashmap that uses buckets to solve the collisions.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

bucket
BucketT* bucket(const size_t index)

Provides an access to the buckets.

bucketCount
size_t bucketCount()

Returns the buckets count.

byKey
auto byKey()
byKeyValue
auto byKeyValue()
byValue
auto byValue()
clear
void clear()

Empties the map.

collisions
size_t collisions()
count
size_t count()
insert
bool insert(ref K key, auto ref V value)
bool insert(K key, V value)

Tries to insert a key-value pair in the set.

minimize
void minimize()

Minimizes the memory used by the map.

opBinaryRight
V* opBinaryRight(auto ref KK key)

Retrieves the value associated to a key.

opIndex
V opIndex(auto ref KK key)

Support for retrieving a value using the array syntax.

opIndexAssign
void opIndexAssign(auto ref V value, auto ref KK key)

Support for assigning using the array syntax.

opIndexAssign
void opIndexAssign(auto ref V2 value, auto ref KK1 key1, auto ref KK2 key2)

Support for assigning to the value when the value is itself an AA.

opIndexOpAssign
void opIndexOpAssign(auto ref VV value, auto ref KK key)

Support for the assignment operators on a value.

opOpAssign
bool opOpAssign(auto ref K key)

Support for appending an element.

remove
bool remove(auto ref K key)

Tries to remove a key from the set.

reserve
void reserve(size_t value)

Reserves buckets for at least N supplemental key-value pairs.

Examples

1 HashMap_AB!(string, size_t) stock;
2 // can insert up to 16 elements without reallocation
3 stock.reserve(15);
4 assert(stock.bucketCount == 16);
5 // appends elements, various syntax allowed
6 stock.insert("pen", 8);
7 stock["gum"] += 32;
8 stock["ruler"] += 12;
9 stock ~= "tape roll";
10 // test for inclusion, various syntax allowed
11 assert("gum" in stock);
12 assert(stock["ruler"] == 12);
13 assert(stock["tape roll"] == 0);
14 // remove something
15 stock.remove("ruler");
16 assert("ruler" !in stock);
17 // empties and frees memory
18 stock.clear;
19 // manually managed implies to destruct by hand
20 import iz.memory;
21 destruct(stock);

Meta