Struct HashTable

Hash table is a data structure that stores pairs of keys and values without any particular order.

struct HashTable(Key, Value, alias hasher)
  
if (isHashFunction!(hasher, Key));

This HashTable is implemented using closed hashing. Hash collisions are resolved with linear probing.

Key should be hashable with hasher. hasher is a callable that accepts an argument of type Key and returns a hash value for it (size_t).

Constructors

NameDescription
this (n, allocator) Constructor.
this (init, allocator) Initializes this HashTable from another one.
this (range, allocator) Constructs the hash table from a forward range.
this (array, allocator) Initializes the hash table from a static array.

Properties

NameTypeDescription
allocator[get] shared(Allocator)
bucketCount[get] size_tReturns current bucket count in the container.
capacity[get] size_tMaximum amount of elements this HashTable can hold without resizing and rehashing. Note that it doesn't mean that the Set will hold exactly capacity elements. capacity tells the size of the container under a best-case distribution of elements.
empty[get] boolTells whether the container contains any elements.
length[get] size_tReturns the number of elements in the container.

Methods

NameDescription
byKey () Returns a bidirectional range that iterats over the keys of this HashTable.
byValue () Returns a bidirectional range that iterats over the values of this HashTable.
clear () Removes all elements.
insert (keyValue) Inserts a new element in the hash table.
insert (range) Inserts a forward range of key/value pairs into the hash table.
opAssign (that) Assigns another hash table.
opBinaryRight (key) Looks for key in this hash table.
opIndex (key) Find the element with the key key.
opIndex () Returns a bidirectional range whose element type is a tuple of a key and the respective value.
opIndexAssign (value, key) Inserts a new value at key or reassigns the element if key already exists in the hash table.
rehash (n) Sets the number of buckets in the container to at least n and rearranges all the elements according to their hash values.
remove (key) Removes the element with the key key.

Aliases

NameDescription
ByKey The range types for HashTable.
ByValue The range types for HashTable.
ConstByValue The range types for HashTable.
ConstRange The range types for HashTable.
KeyValue Type of the key-value pair stored in the hash table.
Range The range types for HashTable.

Parameters

NameDescription
Key Key type.
Value Value type.
hasher Hash function for Key.