Luna::SelfIndexedHashMap
Represents one self-indexed hash map whose key can be extracted from the value, so that it does not need to be stored.
template <typename _Kty, typename _Ty, typename _ExtractKey, typename _Hash, typename _KeyEqual, typename _Alloc>
class Luna::SelfIndexedHashMap
For every value type that the user want to use for self indexed hash map, the user must define one special structure called "key extractor", and passes the type as the _ExtractKey
template argument for the map. In this structure, one operator function const _Kty& operator()(const _Ty& p) const
(or _Kty operator()(const _Ty& p) const
if the key is computed from value) must be defined to fetch the key of the value.
The user must ensure that the key data member is not changed after the element is inserted to the map and before the element is removed from the map, or the behavior is undefined.
Member functions
-
Constructs an empty map.
-
SelfIndexedHashMap(const allocator_type &alloc)
Constructs an empty map with an custom allocator.
-
SelfIndexedHashMap(const SelfIndexedHashMap &rhs)
Constructs a map by coping elements from another map.
-
SelfIndexedHashMap(const SelfIndexedHashMap &rhs, const allocator_type &alloc)
Constructs a map with an custom allocator and with elements copied from another map.
-
SelfIndexedHashMap(SelfIndexedHashMap &&rhs)
Constructs a map by moving elements from another map.
-
SelfIndexedHashMap(SelfIndexedHashMap &&rhs, const allocator_type &alloc)
Constructs a map with an custom allocator and with elements moved from another map.
-
SelfIndexedHashMap & operator=(const SelfIndexedHashMap &rhs)
Replaces elements of the map by coping elements from another map.
-
SelfIndexedHashMap & operator=(SelfIndexedHashMap &&rhs)
Replaces elements of the map by moving elements from another map.
-
Gets one iterator to the first element of the map.
-
Gets one constant iterator to the first element of the map.
-
Gets one constant iterator to the first element of the map.
-
Gets one iterator to the one past last element of the map.
-
Gets one constant iterator to the one past last element of the map.
-
Gets one constant iterator to the one past last element of the map.
-
Checks whether this map is empty, that is, the size of this map is
0
. -
Gets the size of the map, that is, the number of elements in the map.
-
Gets the capacity of the map, that is, the number of elements the hash table can hold before expanding the hash table.
-
Gets the hash table size of the map, that is, the number of slots of the hash table array.
-
Gets the load factor of the map, which can be computed by
(f32)size() / (f32)hash_table_size()
. -
Gets the maximum load factor allowed for the map.
-
Sets the maximum load factor allowed for the map.
-
Removes all elements in the map.
-
Reduces the hash table size to a minimum value that satisfy the maximum load factor limitation.
-
Gets the hash function used by this map.
-
Gets the equality comparison function used by this map.
-
void rehash(usize new_data_table_size)
Changes the data table size and rehashes all elements to insert them to the new data table.
-
Expands the data table size to the specified value.
-
iterator find(const key_type &key)
Finds the specified element in the map.
-
const_iterator find(const key_type &key) const
Finds the specified element in the map.
-
bool contains(const key_type &key) const
Checks whether at least one element with the specified key exists.
-
Pair< iterator, bool > insert(const value_type &value)
Inserts the specified value to the map. The key is extracted from the value.
-
Pair< iterator, bool > insert(value_type &&value)
Inserts the specified value to the map. The key is extracted from the value.
-
Pair< iterator, bool > insert_or_assign(const value_type &value)
Assigns the value to the element with the specified key, or inserts the value pair to the map if such element is not found. The key is extracted from the value.
-
Pair< iterator, bool > insert_or_assign(value_type &&value)
Assigns the value to the element with the specified key, or inserts the value pair to the map if such element is not found. The key is extracted from the value.
-
Pair< iterator, bool > emplace(_Args &&... args)
Constructs one element directly in the map using the provided arguments.
-
iterator erase(const_iterator pos)
Removes one element from the map.
-
usize erase(const key_type &key)
Removes elements with the specified key from the map.
-
void swap(SelfIndexedHashMap &rhs)
Swaps elements of this map with the specified map.
-
allocator_type get_allocator() const
Gets the allocator used by this map.