|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
CRTP mixin providing common operations for open addressing hash tables. More...
#include <hashDry.H>
Classes | |
| class | Iterator |
| Bidirectional iterator for traversing hash table entries. More... | |
| struct | Stats |
| Statistics about hash table performance. More... | |
Public Types | |
| using | Const_Iterator = Aleph::Const_Iterator< Iterator > |
| Read-only iterator: the iterator of a constant table. | |
Public Member Functions | |
| constexpr float | get_lower_alpha () const noexcept |
| Returns the lower load factor threshold for automatic shrinking. | |
| constexpr float | get_upper_alpha () const noexcept |
| Returns the upper load factor threshold for automatic growing. | |
| constexpr bool | get_with_resize () const noexcept |
| Returns whether the table resizes itself. | |
| void | set_with_resize (const bool with_resize) noexcept |
| Turns the automatic resizing on or off. | |
| void | copy_from_table (const HashTbl &other) |
| Copies all entries from another hash table. | |
| void | clean_table () |
| Removes all entries from the table without deallocating storage. | |
| bool | check_resize_before_insert () |
| Makes room for one more key, if the table can take it. | |
| Key * | insert (const Key &key) |
| Inserts a key into the hash table (copy version). | |
| Key * | insert (Key &&key) |
| Inserts a key into the hash table (move version). | |
| Key * | search_or_insert (const Key &key) |
| Searches for a key, inserting it if not found (copy version). | |
| Key * | search_or_insert (Key &&key) |
| Searches for a key, inserting it if not found (move version). | |
| std::pair< Key *, bool > | contains_or_insert (const Key &key) |
| Searches for a key, inserting if not found, with existence flag (copy version). | |
| std::pair< Key *, bool > | contains_or_insert (Key &&key) |
| Searches for a key, inserting if not found, with existence flag (move version). | |
| Key * | append (const Key &key) |
| Alias for insert() (copy version). | |
| Key * | append (Key &&key) |
| Alias for insert() (move version). | |
| constexpr bool | has (const Key &key) const noexcept |
| Checks if a key exists in the table. | |
| constexpr bool | contains (const Key &key) const noexcept |
| Alias for has(). | |
| Key & | find (const Key &key) |
| Finds a key and returns a reference to it. | |
| const Key & | find (const Key &key) const |
| Finds a key and returns a const reference to it. | |
| const Key & | operator[] (const Key &key) const |
| Subscript operator for const access. | |
| const Key & | operator[] (const Key &key) |
| Subscript operator with insertion semantics. | |
| void | remove_ptr (Key *key) |
| Removes an entry by pointer. | |
| size_t | resize (size_t new_size) |
| Resizes the hash table to a new capacity. | |
| void | rehash () |
| Rebuilds the hash table with the same capacity. | |
| void | empty () |
| Clears all entries and resets to default capacity. | |
| void | clear () |
| Empties the container. | |
| constexpr size_t | size () const noexcept |
| Returns the number of entries in the table. | |
| constexpr bool | is_empty () const noexcept |
| Checks if the table is empty. | |
| constexpr size_t | capacity () const noexcept |
| Returns the current capacity of the table. | |
| DynList< Key > | keys () const |
| Returns a list containing all keys in the table. | |
| auto | items () const |
| Alias for keys(). | |
| void | print_stats (const Stats &stats) const |
| Prints statistics to standard output. | |
| constexpr float | current_alpha () const noexcept |
| Returns the current load factor (alpha). | |
Protected Member Functions | |
| void | rebuild (const size_t new_len) |
Places the keys of the table in new_len new buckets. | |
| size_t | rebuild_capacity () const |
| Capacity to rebuild a table that resizes itself with, when its buckets in use are too many. | |
| size_t | capacity_after_insertion () const |
| Capacity that an insertion leaves the table with, or 0 if it keeps it. | |
| void | shrink_after_removal () noexcept |
| Shrinks a table that resizes itself, after a removal took its load factor under the lower threshold. | |
Private Member Functions | |
| HashTbl * | me () |
| Returns a pointer to the derived class (CRTP pattern). | |
| const HashTbl * | const_me () const |
| Returns a const pointer to the derived class (CRTP pattern). | |
| template<class Bucket > | |
| void | store_copy (Bucket *bucket, const Key &key) |
| Stores a copy of a key in the bucket reserved for it. | |
| template<class Bucket > | |
| void | store_move (Bucket *bucket, Key &key) |
| Moves a key into the bucket reserved for it. | |
Static Private Attributes | |
| static constexpr bool | nothrow_key_swap |
| Whether two keys can be swapped without throwing. | |
CRTP mixin providing common operations for open addressing hash tables.
This template class provides shared implementation for hash table operations that are common between ODhashTable (double hashing) and OLhashTable (linear probing). It uses CRTP to achieve static polymorphism, avoiding virtual function overhead while enabling code reuse.
| HashTbl | The derived hash table class (ODhashTable or OLhashTable). Must provide: allocate_bucket(), hard_allocate_bucket(), deallocate_bucket(), test_resize(), search(), table, len, N, deleted_buckets, lower_alpha, upper_alpha, with_resize, current_alpha(), Bucket. |
| Key | The type of keys stored in the table. |
capacity() - 1 keys. A full table that does not resize itself takes no more keys: the insertions return nullptr and operator[] throws std::overflow_error.with_resize is enabled in the derived class, the table automatically:lower_alpha threshold, if the keys fit under upper_alpha in a table of half the capacity. Both remove() and remove_ptr() shrink it; the del() of an iterator does not, so that the iterator stays valid. set_with_resize() turns it on or off after construction.upper_alpha, and when they take it there, it is rebuilt without them: in place, if the keys alone fill less than half of upper_alpha, and twice as large otherwise. So it always keeps an empty bucket. A table that does not resize itself is never rebuilt by itself, so that its keys do not move: the buckets of its removed keys may take its empty buckets, and a search that misses then goes through all of them, until rehash() clears them.| using OhashCommon< HashTbl, Key >::Const_Iterator = Aleph::Const_Iterator<Iterator> |
|
inline |
Alias for insert() (copy version).
Provides STL-like naming for insert operations.
| key | The key to append/insert. |
Definition at line 733 of file hashDry.H.
References OhashCommon< HashTbl, Key >::insert().
Referenced by Aleph::import_network_from_dimacs(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Alias for insert() (move version).
Provides STL-like naming for insert operations.
| key | The key to append/insert (will be moved from). |
Definition at line 746 of file hashDry.H.
References OhashCommon< HashTbl, Key >::insert().
|
inlineconstexprnoexcept |
Returns the current capacity of the table.
Definition at line 964 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by demo_odhash(), OhashCommon< HashTbl, Key >::print_stats(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlineprotected |
Capacity that an insertion leaves the table with, or 0 if it keeps it.
A table that resizes itself is rebuilt when its buckets in use, those of removed keys included, reach the upper threshold. Removing a key does not change how many buckets are in use, so it is enough to check after each insertion.
Definition at line 327 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me(), and OhashCommon< HashTbl, Key >::rebuild_capacity().
|
inline |
Makes room for one more key, if the table can take it.
Called before each insert operation. The table leaves at least one bucket without a key, as a sentinel for probing, so it is full with capacity() - 1 keys. A full table doubles its capacity if automatic resizing is enabled; otherwise it takes no more keys.
The buckets of removed keys are not empty. If they would leave a table that resizes itself without an empty bucket, it is rebuilt without them. A table that does not resize itself is never rebuilt, so that its keys do not move.
A table whose storage was taken by a move has no buckets. It gets here a table of the default capacity, whether or not automatic resizing is enabled.
| std::bad_alloc | If there is no memory for the new buckets, and anything that copying a key throws when the table is rebuilt and its swap may throw. The table is left as it was. |
Definition at line 466 of file hashDry.H.
References OhashCommon< HashTbl, Key >::empty(), OhashCommon< HashTbl, Key >::me(), Primes::next_prime(), OhashCommon< HashTbl, Key >::rebuild(), and OhashCommon< HashTbl, Key >::rebuild_capacity().
Referenced by OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::insert(), OhashCommon< HashTbl, Key >::insert(), OhashCommon< HashTbl, Key >::search_or_insert(), and OhashCommon< HashTbl, Key >::search_or_insert().
|
inline |
Removes all entries from the table without deallocating storage.
Resets all buckets to their initial empty state and sets the entry count to zero. The table capacity remains unchanged.
Definition at line 436 of file hashDry.H.
References OhashCommon< HashTbl, Key >::me().
|
inline |
Empties the container.
| std::bad_alloc | If there is no memory for the new buckets. The table is left as it was. |
Definition at line 949 of file hashDry.H.
References OhashCommon< HashTbl, Key >::empty().
Referenced by TEST(), TEST(), TEST_F(), and Moved_From_Case< MinHash< int > >::use().
|
inlineprivate |
Returns a const pointer to the derived class (CRTP pattern).
Definition at line 181 of file hashDry.H.
Referenced by OhashCommon< HashTbl, Key >::capacity(), OhashCommon< HashTbl, Key >::capacity_after_insertion(), OhashCommon< HashTbl, Key >::current_alpha(), OhashCommon< HashTbl, Key >::get_lower_alpha(), OhashCommon< HashTbl, Key >::get_upper_alpha(), OhashCommon< HashTbl, Key >::get_with_resize(), OhashCommon< HashTbl, Key >::has(), OhashCommon< HashTbl, Key >::is_empty(), OhashCommon< HashTbl, Key >::keys(), OhashCommon< HashTbl, Key >::print_stats(), OhashCommon< HashTbl, Key >::rebuild_capacity(), and OhashCommon< HashTbl, Key >::size().
|
inlineconstexprnoexcept |
Alias for has().
| key | The key to search for. |
Definition at line 769 of file hashDry.H.
References OhashCommon< HashTbl, Key >::has().
|
inline |
Searches for a key, inserting if not found, with existence flag (copy version).
Similar to search_or_insert(), but also indicates whether the key was already present in the table.
| key | The key to search for or insert. |
| Anything | that copying the key throws, and std::bad_alloc if the table cannot grow. The table is left as it was. |
Definition at line 661 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), r, and OhashCommon< HashTbl, Key >::store_copy().
|
inline |
Searches for a key, inserting if not found, with existence flag (move version).
Similar to search_or_insert(), but also indicates whether the key was already present in the table.
| key | The key to search for or insert (moved from on insert). |
| std::bad_alloc | If the table cannot grow, and anything that copying the key throws when the table has to copy it. The table is left as it was; key may have been moved from. |
Definition at line 704 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), r, and OhashCommon< HashTbl, Key >::store_move().
|
inline |
Copies all entries from another hash table.
Copies all BUSY entries from the source table to this table. This table must be empty and have sufficient capacity.
| other | Source hash table to copy from. |
Definition at line 413 of file hashDry.H.
References Aleph::and, and OhashCommon< HashTbl, Key >::me().
Referenced by Aleph::ODhashTable< Key, Cmp >::ODhashTable(), and Aleph::OLhashTable< Key, Cmp >::OLhashTable().
|
inlineconstexprnoexcept |
Returns the current load factor (alpha).
The load factor is the ratio of stored entries to table capacity. A higher load factor means more efficient memory usage but potentially longer probe sequences.
Definition at line 1310 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by OhashCommon< HashTbl, Key >::shrink_after_removal().
|
inline |
Clears all entries and resets to default capacity.
Removes all entries and resets the table to its default initial capacity (Primes::DefaultPrime).
| std::bad_alloc | If there is no memory for the new buckets. The table is left as it was. |
Definition at line 933 of file hashDry.H.
References Primes::DefaultPrime, and OhashCommon< HashTbl, Key >::me().
Referenced by OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::clear(), TEST(), TEST(), TEST(), and TYPED_TEST().
|
inline |
Finds a key and returns a reference to it.
Searches for the key and returns a reference to it. If the key is not found, throws an exception.
| key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 782 of file hashDry.H.
References ah_domain_error_if, and OhashCommon< HashTbl, Key >::me().
Referenced by OhashCommon< HashTbl, Key >::find(), OhashCommon< HashTbl, Key >::operator[](), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and Moved_From_Case< PersistentHashMap< int, int > >::use().
|
inline |
Finds a key and returns a const reference to it.
Const version of find().
| key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 800 of file hashDry.H.
References OhashCommon< HashTbl, Key >::find().
|
inlineconstexprnoexcept |
Returns the lower load factor threshold for automatic shrinking.
When automatic resizing is enabled and the load factor drops below this value after a removal, the table shrinks.
Definition at line 375 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
|
inlineconstexprnoexcept |
Returns the upper load factor threshold for automatic growing.
When automatic resizing is enabled and the load factor would exceed this value, the table grows before insertion.
Definition at line 384 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
|
inlineconstexprnoexcept |
Returns whether the table resizes itself.
Definition at line 389 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
|
inlineconstexprnoexcept |
Checks if a key exists in the table.
| key | The key to search for. |
Definition at line 758 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by OhashCommon< HashTbl, Key >::contains(), TEST(), TEST(), and TEST().
|
inline |
Inserts a key into the hash table (copy version).
Attempts to insert a copy of the key. If the key already exists, the insertion fails and nullptr is returned.
| key | The key to insert. |
| Anything | that copying the key throws, and std::bad_alloc if the table cannot grow. The table is left as it was. |
Definition at line 507 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), and OhashCommon< HashTbl, Key >::store_copy().
Referenced by OhashCommon< HashTbl, Key >::append(), OhashCommon< HashTbl, Key >::append(), demo_odhash(), demo_performance(), main(), Moved_From_Case< PersistentHashMap< int, int > >::make(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TYPED_TEST(), and TYPED_TEST().
|
inline |
Inserts a key into the hash table (move version).
Attempts to insert a key using move semantics. If the key already exists, the insertion fails and nullptr is returned.
| key | The key to insert (will be moved from on success). |
| std::bad_alloc | If the table cannot grow, and anything that copying the key throws when the table has to copy it. The table is left as it was; key may have been moved from. |
Definition at line 541 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), and OhashCommon< HashTbl, Key >::store_move().
|
inlineconstexprnoexcept |
Checks if the table is empty.
Definition at line 959 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by Moved_From_Case< Distinct_Count_Mo_On_Trees< Graph > >::is_empty(), Moved_From_Case< Distinct_Count_Mo_On_Tree_Node< int > >::is_empty(), Moved_From_Case< PersistentHashMap< int, int > >::is_empty(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Moved_From_Case< Distinct_Count_Mo_On_Trees< Graph > >::use(), and Moved_From_Case< Distinct_Count_Mo_On_Tree_Node< int > >::use().
|
inline |
|
inline |
Returns a list containing all keys in the table.
Creates and returns a DynList containing copies of all keys stored in the hash table.
Definition at line 1247 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< PersistentHashMap< int, int > >::use().
|
inlineprivate |
Returns a pointer to the derived class (CRTP pattern).
Definition at line 176 of file hashDry.H.
Referenced by OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::clean_table(), Aleph::OLhashTable< int >::contains(), OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::copy_from_table(), OhashCommon< HashTbl, Key >::empty(), OhashCommon< HashTbl, Key >::find(), OhashCommon< HashTbl, Key >::insert(), OhashCommon< HashTbl, Key >::insert(), OhashCommon< HashTbl, Key >::rebuild(), OhashCommon< HashTbl, Key >::rehash(), OhashCommon< HashTbl, Key >::remove_ptr(), OhashCommon< HashTbl, Key >::resize(), OhashCommon< HashTbl, Key >::search_or_insert(), OhashCommon< HashTbl, Key >::search_or_insert(), OhashCommon< HashTbl, Key >::set_with_resize(), OhashCommon< HashTbl, Key >::shrink_after_removal(), and OhashCommon< HashTbl, Key >::store_copy().
|
inline |
Subscript operator with insertion semantics.
Returns a reference to the key. If the key doesn't exist, it is inserted first.
| key | The key to access or insert. |
| std::overflow_error | If the key is not in the table and the table is full and does not resize itself. |
| Anything | that copying the key throws, and std::bad_alloc if the table cannot grow. The table is left as it was. |
Definition at line 830 of file hashDry.H.
References ah_overflow_error_if, and OhashCommon< HashTbl, Key >::search_or_insert().
|
inline |
Subscript operator for const access.
Returns a const reference to the key. Equivalent to find().
| key | The key to access. |
| std::domain_error | If the key is not found. |
Definition at line 813 of file hashDry.H.
References OhashCommon< HashTbl, Key >::find().
|
inline |
Prints statistics to standard output.
Displays formatted statistics including capacity, size, bucket states, load factor, and probe length distribution.
| stats | Statistics object to print. |
Definition at line 1288 of file hashDry.H.
References OhashCommon< HashTbl, Key >::capacity(), OhashCommon< HashTbl, Key >::const_me(), OhashCommon< HashTbl, Key >::Stats::lens, OhashCommon< HashTbl, Key >::Stats::max_len, OhashCommon< HashTbl, Key >::Stats::num_busy, OhashCommon< HashTbl, Key >::Stats::num_deleted, OhashCommon< HashTbl, Key >::Stats::num_empty, OhashCommon< HashTbl, Key >::size(), and Aleph::DynArray< T >::size().
|
inlineprotected |
Places the keys of the table in new_len new buckets.
The keys are swapped into the new buckets. A key whose swap may throw is copied instead, so that the old buckets keep every key until all of them are placed. The buckets of removed keys are left behind.
| new_len | Number of new buckets. It must leave an empty bucket. |
| std::overflow_error | If the bytes of the new buckets do not fit in a size_t, std::bad_alloc if there is no memory for them, and anything that copying a key throws. The table is left as it was. |
Definition at line 255 of file hashDry.H.
References OhashCommon< HashTbl, Key >::me().
Referenced by OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::rehash(), and OhashCommon< HashTbl, Key >::resize().
|
inlineprotected |
Capacity to rebuild a table that resizes itself with, when its buckets in use are too many.
The buckets in use include the ones of removed keys, which a search does not stop at, and a rebuild leaves behind. If the keys alone fill less than half of the upper threshold, the table keeps its capacity, so that many insertions come before it has to be rebuilt again; otherwise it doubles.
Definition at line 309 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me(), and Primes::next_prime().
Referenced by OhashCommon< HashTbl, Key >::capacity_after_insertion(), and OhashCommon< HashTbl, Key >::check_resize_before_insert().
|
inline |
Rebuilds the hash table with the same capacity.
Creates a new internal table with the same capacity and re-inserts all entries. This can help improve performance after many deletions by eliminating deleted bucket markers. A table that does not resize itself never does it by itself.
| std::bad_alloc | If there is no memory for the new buckets, and anything that copying a key throws when its swap may throw. The table is left as it was. |
Definition at line 915 of file hashDry.H.
References OhashCommon< HashTbl, Key >::me(), and OhashCommon< HashTbl, Key >::rebuild().
Referenced by Aleph::ODhashTable< Key, Cmp >::set_second_hash_fct().
|
inline |
Removes an entry by pointer.
Removes the entry pointed to by the given pointer. The pointer must have been obtained from this table (via insert, search, etc.).
If automatic resizing is enabled and the load factor drops below the lower threshold, the table shrinks to about half its capacity, provided the keys fit there under the upper threshold and leave an empty bucket. With a lower threshold over one half they may not fit; the table then keeps its capacity until enough keys are removed. If there is no memory for the smaller table, the table keeps its capacity too, and the key stays removed.
| key | Pointer to the key to remove (must be in this table). |
| std::invalid_argument | If key does not point into the table. |
| std::domain_error | If the key of its bucket was removed. |
Definition at line 860 of file hashDry.H.
References ah_domain_error_if, ah_invalid_argument_if, OhashCommon< HashTbl, Key >::me(), and OhashCommon< HashTbl, Key >::shrink_after_removal().
|
inline |
Resizes the hash table to a new capacity.
Changes the table capacity to the specified size and rehashes all entries. The new size must be large enough to hold all current entries plus at least one empty sentinel bucket.
| new_size | The new capacity (should be a prime number). |
| std::overflow_error | If new_size is too small for current entries, or the bytes of that many buckets do not fit in a size_t. |
| std::bad_alloc | If there is no memory for the new buckets, and anything that copying a key throws when its swap may throw. The table is left as it was. |
Definition at line 888 of file hashDry.H.
References ah_overflow_error_if, OhashCommon< HashTbl, Key >::me(), and OhashCommon< HashTbl, Key >::rebuild().
Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson(), OhashCommon< HashTbl, Key >::shrink_after_removal(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_arcs().
|
inline |
Searches for a key, inserting it if not found (copy version).
If the key exists, returns a pointer to it. Otherwise, inserts a copy of the key and returns a pointer to the newly inserted key.
| key | The key to search for or insert. |
| Anything | that copying the key throws, and std::bad_alloc if the table cannot grow. The table is left as it was. |
Definition at line 575 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), r, and OhashCommon< HashTbl, Key >::store_copy().
Referenced by OhashCommon< HashTbl, Key >::operator[]().
|
inline |
Searches for a key, inserting it if not found (move version).
If the key exists, returns a pointer to it. Otherwise, inserts the key using move semantics and returns a pointer to the newly inserted key.
| key | The key to search for or insert (moved from on insert). |
| std::bad_alloc | If the table cannot grow, and anything that copying the key throws when the table has to copy it. The table is left as it was; key may have been moved from. |
Definition at line 614 of file hashDry.H.
References OhashCommon< HashTbl, Key >::check_resize_before_insert(), OhashCommon< HashTbl, Key >::me(), r, and OhashCommon< HashTbl, Key >::store_move().
|
inlinenoexcept |
Turns the automatic resizing on or off.
The change applies from the next insertion or removal on: turning it on does not rebuild the table at once. Turned off, the table keeps its capacity and its keys do not move by themselves; a full table then takes no more keys.
| with_resize | true for the table to grow and shrink by itself. |
Definition at line 400 of file hashDry.H.
References OhashCommon< HashTbl, Key >::me().
|
inlineprotectednoexcept |
Shrinks a table that resizes itself, after a removal took its load factor under the lower threshold.
The table goes to about half its capacity, provided the keys fit there under the upper threshold and leave an empty bucket. With a lower threshold over one half they may not fit; the table then keeps its capacity until enough keys are removed. If the smaller table cannot be built, because there is no memory for it or a key cannot be copied, the table keeps its capacity too: the removal stands.
Definition at line 346 of file hashDry.H.
References Aleph::and, OhashCommon< HashTbl, Key >::current_alpha(), OhashCommon< HashTbl, Key >::me(), Primes::next_prime(), and OhashCommon< HashTbl, Key >::resize().
Referenced by Aleph::ODhashTable< Key, Cmp >::remove(), Aleph::OLhashTable< Key, Cmp >::remove(), and OhashCommon< HashTbl, Key >::remove_ptr().
|
inlineconstexprnoexcept |
Returns the number of entries in the table.
Definition at line 954 of file hashDry.H.
References OhashCommon< HashTbl, Key >::const_me().
Referenced by Aleph::analyze_fit(), Aleph::boyer_moore_horspool_search(), Aleph::damerau_levenshtein_distance(), demo_odhash(), demo_performance(), Aleph::find_disjoint_negative_cycles(), Moved_From_Case< Field_Grid >::fingerprint(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::fit(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::fit_parallel(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::fit_ridge(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::fit_weighted(), Moved_From_Case< Field_Grid >::is_empty(), Moved_From_Case< Distinct_Count_Mo_On_Trees< Graph > >::is_empty(), Moved_From_Case< Distinct_Count_Mo_On_Tree_Node< int > >::is_empty(), Moved_From_Case< MinHash< int > >::is_empty(), Aleph::longest_common_subsequence(), Aleph::longest_common_substring(), make_matrix(), Aleph::map_to_Array(), Aleph::maphash_to_Array(), Aleph::maptree_to_Array(), Aleph::matrix_dims(), Aleph::CA::Graph_Lattice< T >::max_degree(), Aleph::most_negative_cycle_bounded(), Aleph::FlatMap< Key, T, Compare >::operator==(), OhashCommon< HashTbl, Key >::print_stats(), Aleph::rabin_karp_search(), Aleph::solve_transportation(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TYPED_TEST(), Moved_From_Case< Distinct_Count_Mo_On_Trees< Graph > >::use(), Moved_From_Case< Distinct_Count_Mo_On_Tree_Node< int > >::use(), and Moved_From_Case< PersistentHashMap< int, int > >::use().
|
inlineprivate |
Stores a copy of a key in the bucket reserved for it.
If copying the key throws, the reservation is undone, so the table does not keep a bucket that counts as an entry and holds another key.
| Bucket | The bucket type of the table. It is a parameter because the table is not a complete type here. |
| bucket | Bucket that allocate_bucket() or hard_allocate_bucket() has just reserved for key. |
| key | The key to store. |
| Anything | that copying the key throws. The table is left as it was before the bucket was reserved. |
Definition at line 203 of file hashDry.H.
References OhashCommon< HashTbl, Key >::me().
Referenced by OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::insert(), OhashCommon< HashTbl, Key >::search_or_insert(), and OhashCommon< HashTbl, Key >::store_move().
|
inlineprivate |
Moves a key into the bucket reserved for it.
The key and the previous content of the bucket are swapped. A key whose swap may throw is copied instead: a copy that fails leaves the key intact, so the reservation can be undone.
| Bucket | The bucket type of the table. |
| bucket | Bucket that allocate_bucket() or hard_allocate_bucket() has just reserved for key. |
| key | The key to store. |
| Anything | that copying the key throws, when it is copied. The table is left as it was before the bucket was reserved. |
Definition at line 233 of file hashDry.H.
References OhashCommon< HashTbl, Key >::nothrow_key_swap, and OhashCommon< HashTbl, Key >::store_copy().
Referenced by OhashCommon< HashTbl, Key >::contains_or_insert(), OhashCommon< HashTbl, Key >::insert(), and OhashCommon< HashTbl, Key >::search_or_insert().
|
staticconstexprprivate |
Whether two keys can be swapped without throwing.
The keys whose swap can throw are copied instead, so that a failure leaves the table as it was.
Definition at line 186 of file hashDry.H.
Referenced by Aleph::OLhashTable< int >::contains(), and OhashCommon< HashTbl, Key >::store_move().