![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
The class for generic Hash Tables. More...
#include <agrum/base/core/hashTable.h>
Public Types | |
| using | Bucket = HashTableBucket< Key, Val > |
| The buckets where data are stored. | |
| using | key_type = Key |
| Types for STL compliance. | |
| using | mapped_type = Val |
| Types for STL compliance. | |
| using | value_type = std::pair< const Key, Val > |
| Types for STL compliance. | |
| using | reference = value_type& |
| Types for STL compliance. | |
| using | const_reference = const value_type& |
| Types for STL compliance. | |
| using | pointer = value_type* |
| Types for STL compliance. | |
| using | const_pointer = const value_type* |
| Types for STL compliance. | |
| using | size_type = Size |
| Types for STL compliance. | |
| using | difference_type = std::ptrdiff_t |
| Types for STL compliance. | |
| using | iterator = HashTableIterator< Key, Val > |
| Types for STL compliance. | |
| using | const_iterator = HashTableConstIterator< Key, Val > |
| Types for STL compliance. | |
| using | iterator_safe = HashTableIteratorSafe< Key, Val > |
| Types for STL compliance. | |
| using | const_iterator_safe = HashTableConstIteratorSafe< Key, Val > |
| Types for STL compliance. | |
Public Member Functions | |
Constructors / Destructors | |
| HashTable (Size size_param=HashTableConst::default_size, bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy) | |
| Default constructor. | |
| HashTable (std::initializer_list< std::pair< Key, Val > > list) | |
| Initializer list constructor. | |
| HashTable (const HashTable< Key, Val > &from) | |
| Copy constructor. | |
| HashTable (HashTable< Key, Val > &&from) noexcept | |
| Move constructor. | |
| ~HashTable () | |
| Class destructor. | |
Iterators | |
| const iterator & | end () noexcept |
| Returns the unsafe iterator pointing to the end of the hashtable. | |
| const const_iterator & | end () const noexcept |
| Returns the unsafe const_iterator pointing to the end of the hashtable. | |
| const const_iterator & | cend () const noexcept |
| Returns the unsafe const_iterator pointing to the end of the hashtable. | |
| iterator | begin () |
| Returns an unsafe iterator pointing to the beginning of the hashtable. | |
| const_iterator | begin () const |
| Returns an unsafe const_iterator pointing to the beginning of the hashtable. | |
| const_iterator | cbegin () const |
| Returns an unsafe const_iterator pointing to the beginning of the hashtable. | |
| const iterator_safe & | endSafe () noexcept |
| Returns the safe iterator pointing to the end of the hashtable. | |
| const const_iterator_safe & | endSafe () const noexcept |
| Returns the safe const_iterator pointing to the end of the hashtable. | |
| const const_iterator_safe & | cendSafe () const noexcept |
| Returns the safe const_iterator pointing to the end of the hashtable. | |
| iterator_safe | beginSafe () |
| Returns the safe iterator pointing to the beginning of the hashtable. | |
| const_iterator_safe | beginSafe () const |
| Returns the safe const_iterator pointing to the beginning of the hashtable. | |
| const_iterator_safe | cbeginSafe () const |
| Returns the safe const_iterator pointing to the beginning of the hashtable. | |
Operators | |
| HashTable< Key, Val > & | operator= (const HashTable< Key, Val > &from) |
| Copy operator. | |
| HashTable< Key, Val > & | operator= (HashTable< Key, Val > &&from) noexcept |
| Move operator. | |
| Val & | operator[] (const Key &key) |
| Returns a reference on the value the key of which is passed in argument. | |
| const Val & | operator[] (const Key &key) const |
| returns a reference on the value the key of which is passed in argument | |
| template<typename K> | |
| Val & | operator[] (const K &key) |
| Heterogeneous lookup: operator[] without string allocation (accepts string_view, const char*, etc.). | |
| template<typename K> | |
| const Val & | operator[] (const K &key) const |
| Heterogeneous lookup: operator[] const without string allocation. | |
| bool | operator== (const HashTable< Key, Val > &from) const |
| Checks whether two hashtables contain the same elements. | |
Fine tuning | |
| Size | capacity () const noexcept |
| Returns the number of slots in the 'nodes' vector of the hashtable. | |
| void | resize (Size new_size) |
| Changes the number of slots in the 'nodes' vector of the hash table. | |
| void | setResizePolicy (const bool new_policy) noexcept |
| Enables the user to change dynamically the resizing policy. | |
| bool | resizePolicy () const noexcept |
| Returns the current resizing policy. | |
| void | setKeyUniquenessPolicy (const bool new_policy) noexcept |
| Enables the user to change dynamically the policy for checking whether there can exist several elements in the table with identical keys. | |
| bool | keyUniquenessPolicy () const noexcept |
| Returns the current checking policy. | |
Accessors / Modifiers | |
| Size | size () const noexcept |
| Returns the number of elements stored into the hashtable. | |
| bool | exists (const Key &key) const |
| Checks whether there exists an element with a given key in the hashtable. | |
| template<typename K> | |
| bool | exists (const K &key) const |
| Heterogeneous lookup: exists() without string allocation (accepts string_view, const char*, etc.). | |
| optional_ref< Val > | tryGet (const Key &key) |
| Returns a pointer to the value associated with a given key, or nullptr if the key does not exist. | |
| optional_ref< const Val > | tryGet (const Key &key) const |
| Returns a pointer to the value associated with a given key, or nullptr if the key does not exist. | |
| template<typename K> | |
| optional_ref< Val > | tryGet (const K &key) |
| Heterogeneous lookup: tryGet() without string allocation (accepts string_view, const char*, etc.). | |
| template<typename K> | |
| optional_ref< const Val > | tryGet (const K &key) const |
| Heterogeneous lookup: tryGet() const without string allocation. | |
| value_type & | insert (const Key &key, const Val &val) |
| Adds a new element (actually a copy of this element) into the hash table. | |
| value_type & | insert (Key &&key, Val &&val) |
| Moves a new element in the hash table. | |
| value_type & | insert (const std::pair< Key, Val > &elt) |
| Adds a new element (actually a copy of this element) into the hash table. | |
| value_type & | insert (std::pair< Key, Val > &&elt) |
| Moves a new element in the hash table. | |
| template<typename... Args> | |
| value_type & | emplace (Args &&... args) |
| Emplace a new element into the hashTable. | |
| mapped_type & | getWithDefault (const Key &key, const Val &default_value) |
| Returns a reference on the element the key of which is passed in argument. | |
| mapped_type & | getWithDefault (Key &&key, Val &&default_value) |
| Returns a reference on the element the key of which is passed in argument. | |
| void | set (const Key &key, const Val &default_value) |
| Add a new property or modify it if it already existed. | |
| void | reset (const Key &key) |
| Removes a property (i.e., remove an element). | |
| void | erase (const Key &key) |
| Removes a given element from the hash table. | |
| template<typename K> | |
| void | erase (const K &key) |
| Heterogeneous lookup: erase() without string allocation (accepts string_view, const char*, etc.). | |
| void | erase (const iterator_safe &iter) |
| Removes a given element from the hash table. | |
| void | erase (const const_iterator_safe &iter) |
| Removes a given element from the hash table. | |
| void | eraseByVal (const Val &val) |
| Removes a given element from the hash table. | |
| const Key & | keyByVal (const Val &val) const |
| Returns a reference on the key given a value. | |
| const Key & | key (const Key &key) const |
| Returns a reference on a given key. | |
| optional_ref< const Key > | tryGetKey (const Key &key) const |
| Returns an optional reference to a given key, or nullptr if the hash table does not contain it. | |
| void | eraseAllVal (const Val &val) |
| Removes all the elements having a certain value from the hash table. | |
| void | clear () |
| Removes all the elements in the hash table. | |
| bool | empty () const noexcept |
| Indicates whether the hash table is empty. | |
| template<typename Mount> | |
| HashTable< Key, Mount > | map (Mount(*f)(Val), Size size=Size(0), bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy) const |
| Transforms a hashtable of vals into a hashtable of mountains. | |
| template<typename Mount> | |
| HashTable< Key, Mount > | map (Mount(*f)(Val &), Size size=Size(0), bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy) const |
| Transforms a hashtable of vals into a hashtable of mountains. | |
| template<typename Mount> | |
| HashTable< Key, Mount > | map (Mount(*f)(const Val &), Size size=Size(0), bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy) const |
| Transforms a hashtable of vals into a hashtable of mountains. | |
| template<typename Mount> | |
| HashTable< Key, Mount > | map (const Mount &val, Size size=Size(0), bool resize_pol=HashTableConst::default_resize_policy, bool key_uniqueness_pol=HashTableConst::default_uniqueness_policy) const |
| Creates a hashtable of mounts with a given value from a hashtable of vals. | |
Private Member Functions | |
| void | _erase_ (HashTableBucket< Key, Val > *bucket, Size index) |
| Erases a given bucket. | |
| void | _copy_ (const HashTable< Key, Val > &table) |
| A function used to perform copies of HashTables. | |
| void | _create_ (Size size) |
| Used by all default constructors (general and specialized). | |
| void | _clearIterators_ () |
| Clear all the safe iterators. | |
| void | _insert_ (Bucket *bucket) |
| Adds a new element (actually a copy of this element) in the hash table. | |
Private Attributes | |
| std::vector< HashTableList< Key, Val > > | _nodes_ |
| The hash table is represented as a vector of chained lists. | |
| Size | _size_ |
| The number of nodes in vector ' __nodes'. | |
| Size | _nb_elements_ {Size(0)} |
| Number of elements of type Val stored in the hash table. | |
| HashFunc< Key > | _hash_func_ |
| The function used to hash keys (may change when the table is resized). | |
| bool | _resize_policy_ {true} |
| Is resizing performed automatically? | |
| bool | _key_uniqueness_policy_ {true} |
| Shall we check for key uniqueness in the table? | |
| Size | _begin_index_ {std::numeric_limits< Size >::max()} |
| Returns where the begin index should be. | |
| std::vector< HashTableConstIteratorSafe< Key, Val > * > | _safe_iterators_ |
| The list of safe iterators pointing to the hash table. | |
Friends | |
| class | HashTableIterator< Key, Val > |
| Friends to optimize the access to data, iterators must be friends. | |
| class | HashTableConstIterator< Key, Val > |
| Friends to optimize the access to data, iterators must be friends. | |
| class | HashTableIteratorSafe< Key, Val > |
| Friends to optimize the access to data, iterators must be friends. | |
| class | HashTableConstIteratorSafe< Key, Val > |
| Friends to optimize the access to data, iterators must be friends. | |
| template<typename T1, typename T2> | |
| class | Bijection |
| For bijections to quickly access data. | |
| std::ostream & | operator<< (std::ostream &s, const HashTable< Key, Val > &table) |
| Prints the content of a gum::HashTable in the stream. | |
| std::ostream & | operator<< (std::ostream &s, const HashTable< Key *, Val > &table) |
| Prints the content of a gum::HashTable with pointers key in the stream. | |
The class for generic Hash Tables.
In aGrUM, a hashtable is a vector of chained lists (collision problems are fixed by chaining). Each slot of the vector contains a list of elements sharing the same hashed value. To be computationally efficient, the hash table should not contain too many elements as compared to its number of slots. Therefore, it is sometimes useful to resize the chained lists vector. aGrUM's hash tables are designed to automatically double their size when there is in average more than 3 elements per slot. However, when memory consumption is a concern, this feature can be turned off either by passing false as an optional resize_pol argument to the constructor of the hash table or by using method setResizePolicy when the instance of the class has already been constructed. Similarly, the default number of slots of the hash table may be parameterized as an optional argument of the constructor (size_param). Beware: when inserting elements of a given class into a hash table, unless the element is an r-value, only a copy of this element is stored into the table (this is compulsory if the hashtable is to be generic and can be used to store both complex classes and built-in types like integers). HashTable have different kinds of iterators: HashTableIteratorSafe and HashTableConstIteratorSafe (a.k.a. HashTable<>::iterator_safe and HashTable<>::const_iterator_safe) allow safe parsing of the hash tables. By safe, we mean that whenever the element pointed to by such an iterator is removed from the hashtable, accessing it through the iterator (*iter) does not result in a segmentation fault but rather in an exception being thrown. This safety is ensured at a very low cost (actually, our experiments show that our HashTables and HashTable's safe iterators significantly outperform the standard library unordered_maps). Of course, if there is no possibility for an iterator to point to a deleted element, the user can use "unsafe" iterators HashTableIterator and HashTableConstIterator (a.k.a. HashTable<>::iterator and HashTable<>::const_iterator). These iterators are slightly faster than their safe counterparts. However, as in the standard library, accessing through them a deleted element usually results in a mess (most probably a segfault).
| Key | The type for keys in a gum::HashTable. |
| Val | The type for values in a gum::HashTable. |
Definition at line 640 of file hashTable.h.
| using gum::HashTable< Key, Val >::Bucket = HashTableBucket< Key, Val > |
The buckets where data are stored.
Definition at line 660 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_iterator = HashTableConstIterator< Key, Val > |
Types for STL compliance.
Definition at line 654 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_iterator_safe = HashTableConstIteratorSafe< Key, Val > |
Types for STL compliance.
Definition at line 656 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_pointer = const value_type* |
Types for STL compliance.
Definition at line 650 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_reference = const value_type& |
Types for STL compliance.
Definition at line 648 of file hashTable.h.
| using gum::HashTable< Key, Val >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 652 of file hashTable.h.
| using gum::HashTable< Key, Val >::iterator = HashTableIterator< Key, Val > |
Types for STL compliance.
Definition at line 653 of file hashTable.h.
| using gum::HashTable< Key, Val >::iterator_safe = HashTableIteratorSafe< Key, Val > |
Types for STL compliance.
Definition at line 655 of file hashTable.h.
| using gum::HashTable< Key, Val >::key_type = Key |
Types for STL compliance.
Definition at line 644 of file hashTable.h.
| using gum::HashTable< Key, Val >::mapped_type = Val |
Types for STL compliance.
Definition at line 645 of file hashTable.h.
| using gum::HashTable< Key, Val >::pointer = value_type* |
Types for STL compliance.
Definition at line 649 of file hashTable.h.
| using gum::HashTable< Key, Val >::reference = value_type& |
Types for STL compliance.
Definition at line 647 of file hashTable.h.
| using gum::HashTable< Key, Val >::size_type = Size |
Types for STL compliance.
Definition at line 651 of file hashTable.h.
| using gum::HashTable< Key, Val >::value_type = std::pair< const Key, Val > |
Types for STL compliance.
Definition at line 646 of file hashTable.h.
|
explicit |
Default constructor.
The true capacity (vector's size) of the hashtable will be the lowest number greater than or equal to size_param that is also a power of 2. The second optional argument is the resizing policy. By default, each time there is an average of 3 elements by node, the size of the hashtable is automatically multiplied by 2. But the user may pass false as argument to resize_pol to disable this feature.
| size_param | The initial size of the gum::HashTable. |
| resize_pol | The policy for resizing the hashtable when new elements are added (possible values: true = automatic resize and false = manual resize). |
| key_uniqueness_pol | Uniqueness policy : should we prevent inserting the same key more than once in the table? |
Definition at line 314 of file hashTable_tpl.h.
References HashTable(), _create_(), gum::_hashTableLog2_(), _key_uniqueness_policy_, _resize_policy_, and _size_.
Referenced by HashTable(), HashTable(), HashTable(), HashTable(), ~HashTable(), _copy_(), map(), map(), map(), map(), operator=(), operator=(), operator==(), operator[](), and operator[]().
|
explicit |
Initializer list constructor.
| list | The initialized list. |
Definition at line 326 of file hashTable_tpl.h.
References HashTable(), _create_(), gum::_hashTableLog2_(), _size_, insert(), and size().
| gum::HashTable< Key, Val >::HashTable | ( | const HashTable< Key, Val > & | from | ) |
Copy constructor.
This creates a new hashtable the content of which is similar to that of the table passed in argument. Beware: similar does not mean that both tables share the same objects, but rather that the objects stored in the newly created table are copies of those of the table passed in argument. In particular, the new hash table inherits the parameters (resize policy, uniqueness policy) of table 'from'.
| from | The gum::HashTable to copy. |
Definition at line 342 of file hashTable_tpl.h.
References HashTable(), _begin_index_, _copy_(), _create_(), _key_uniqueness_policy_, _resize_policy_, and _size_.
|
noexcept |
Move constructor.
| from | The gum::HashTable to move. |
Definition at line 356 of file hashTable_tpl.h.
References HashTable(), _nodes_, and _size_.
| gum::HashTable< Key, Val >::~HashTable | ( | ) |
Class destructor.
Definition at line 393 of file hashTable_tpl.h.
References HashTable(), and _clearIterators_().
|
private |
Clear all the safe iterators.
Definition at line 372 of file hashTable_tpl.h.
References _safe_iterators_, and clear().
Referenced by ~HashTable(), and clear().
|
private |
A function used to perform copies of HashTables.
This code is shared by the copy constructor and the copy operator. The function ensures that when a memory allocation problem occurs:
The function assumes that both this and table have arrays ' __nodes' of the same size.
| table | The gum::HashTable to copy. |
Definition at line 279 of file hashTable_tpl.h.
References HashTable(), and _size_.
Referenced by HashTable().
|
private |
Used by all default constructors (general and specialized).
| size | The size of the gum::HashTable to create. |
Definition at line 305 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and size().
Referenced by HashTable(), HashTable(), and HashTable().
|
private |
Erases a given bucket.
Definition at line 821 of file hashTable_tpl.h.
References _nb_elements_, _nodes_, and _safe_iterators_.
Referenced by erase(), erase(), and erase().
|
private |
Adds a new element (actually a copy of this element) in the hash table.
If there already exists an element with the same key in the list and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| bucket | The bucket inserted in the hash table. |
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
Definition at line 722 of file hashTable_tpl.h.
References _hash_func_, _key_uniqueness_policy_, _nodes_, exists(), GUM_ERROR, and gum::HashTableBucket< Key, Val >::key().
Referenced by emplace(), insert(), insert(), and insert().
| HashTable< Key, Val >::iterator gum::HashTable< Key, Val >::begin | ( | ) |
Returns an unsafe iterator pointing to the beginning of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 490 of file hashTable_tpl.h.
References _nb_elements_, and end().
Referenced by gum::MultiDimFunctionGraphOperator< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_ELEMENT, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), keyByVal(), map(), map(), operator==(), and gum::learning::SimpleMiic::orientationMiic_().
| HashTable< Key, Val >::const_iterator gum::HashTable< Key, Val >::begin | ( | ) | const |
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 497 of file hashTable_tpl.h.
References _nb_elements_, and end().
| HashTable< Key, Val >::iterator_safe gum::HashTable< Key, Val >::beginSafe | ( | ) |
Returns the safe iterator pointing to the beginning of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 528 of file hashTable_tpl.h.
References _nb_elements_, and endSafe().
Referenced by gum::DAGCycleDetector::hasCycleFromModifications(), gum::LeafAggregator::leavesMap(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::toDot(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| HashTable< Key, Val >::const_iterator_safe gum::HashTable< Key, Val >::beginSafe | ( | ) | const |
Returns the safe const_iterator pointing to the beginning of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 535 of file hashTable_tpl.h.
References _nb_elements_, and endSafe().
|
noexcept |
Returns the number of slots in the 'nodes' vector of the hashtable.
The method runs in constant time.
Definition at line 586 of file hashTable_tpl.h.
References _size_.
Referenced by gum::ArcGraphPart::ArcGraphPart().
| HashTable< Key, Val >::const_iterator gum::HashTable< Key, Val >::cbegin | ( | ) | const |
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 504 of file hashTable_tpl.h.
References _nb_elements_, and cend().
Referenced by gum::learning::StructuralConstraintSliceOrder::StructuralConstraintSliceOrder(), gum::DAGCycleDetector::_addWeightedSet_(), gum::BijectionImplementation< T1, T2, Gen >::_copy_(), gum::DAGCycleDetector::_delWeightedSet_(), gum::DAGCycleDetector::_restrictWeightedSet_(), gum::DAGCycleDetector::addArc(), gum::DAGCycleDetector::eraseArc(), gum::DAGCycleDetector::hasCycleFromModifications(), and gum::Set< Key >::operator+().
| HashTable< Key, Val >::const_iterator_safe gum::HashTable< Key, Val >::cbeginSafe | ( | ) | const |
Returns the safe const_iterator pointing to the beginning of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 542 of file hashTable_tpl.h.
References _nb_elements_, and cendSafe().
Referenced by gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), and gum::LeastSquareTestPolicy< GUM_ELEMENT >::add().
|
noexcept |
Returns the unsafe const_iterator pointing to the end of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 485 of file hashTable_tpl.h.
Referenced by gum::learning::StructuralConstraintSliceOrder::StructuralConstraintSliceOrder(), gum::DAGCycleDetector::_addWeightedSet_(), gum::BijectionImplementation< T1, T2, Gen >::_copy_(), gum::DAGCycleDetector::_delWeightedSet_(), gum::DAGCycleDetector::_restrictWeightedSet_(), gum::DAGCycleDetector::addArc(), cbegin(), gum::DAGCycleDetector::eraseArc(), gum::DAGCycleDetector::hasCycleFromModifications(), and gum::Set< Key >::operator+().
|
noexcept |
Returns the safe const_iterator pointing to the end of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 523 of file hashTable_tpl.h.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::LeastSquareTestPolicy< GUM_ELEMENT >::add(), cbeginSafe(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| void gum::HashTable< Key, Val >::clear | ( | ) |
Removes all the elements in the hash table.
The function does not resize the nodes vector (even if the size of this one has been increased after the creation of the hash table) and it resets the iterators on the hash table to end. The method runs in linear time w.r.t. the number of iterators pointing to the hash table.
Definition at line 379 of file hashTable_tpl.h.
References _clearIterators_(), _nodes_, _size_, and clear().
Referenced by _clearIterators_(), gum::MultiDimFunctionGraphOperator< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_ELEMENT, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), and clear().
| HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::emplace | ( | Args &&... | args | ) |
Emplace a new element into the hashTable.
If there already exists an element with the same key in the list and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
| args | The element to emplace. |
Definition at line 787 of file hashTable_tpl.h.
References _insert_(), gum::HashTableBucket< Key, Val >::elt(), and gum::HashTableBucket< Key, Val >::EMPLACE.
|
noexcept |
Indicates whether the hash table is empty.
Definition at line 928 of file hashTable_tpl.h.
References _nb_elements_.
Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::causalImpact(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), gum::BayesBall::relevantTensors(), and gum::dSeparationAlgorithm::relevantTensors().
|
noexcept |
Returns the unsafe const_iterator pointing to the end of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 479 of file hashTable_tpl.h.
|
noexcept |
Returns the unsafe iterator pointing to the end of the hashtable.
Unsafe iterators are slightly faster than safe iterators. However, BE CAREFUL when using them: they should ONLY be used when you have the guarantee that they will never point to a deleted element. If unsure, prefer using the safe iterators (those are only slightly slower).
Definition at line 473 of file hashTable_tpl.h.
Referenced by gum::MultiDimFunctionGraphOperator< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_ELEMENT, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), begin(), begin(), keyByVal(), map(), map(), operator==(), and gum::learning::SimpleMiic::orientationMiic_().
|
noexcept |
Returns the safe const_iterator pointing to the end of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 517 of file hashTable_tpl.h.
|
noexcept |
Returns the safe iterator pointing to the end of the hashtable.
Safe iterators are slightly slower than unsafe ones but they guarantee that you will never get a segfault if they try to access to a deleted element or if they try a ++ operation from a deleted element.
Definition at line 511 of file hashTable_tpl.h.
Referenced by beginSafe(), beginSafe(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::LeafAggregator::leavesMap(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::toDot(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| void gum::HashTable< Key, Val >::erase | ( | const const_iterator_safe & | iter | ) |
Removes a given element from the hash table.
This method updates all the safe iterators pointing to the deleted element, i.e., when trying to dereference those iterators, an exception will be raised because they will know that the element they point to no longer exists.
| iter | An iterator over the element to remove. |
Definition at line 876 of file hashTable_tpl.h.
References _erase_(), gum::HashTableConstIteratorSafe< Key, Val >::_getBucket_(), and gum::HashTableConstIteratorSafe< Key, Val >::_getIndex_().
| void gum::HashTable< Key, Val >::erase | ( | const iterator_safe & | iter | ) |
Removes a given element from the hash table.
This method updates all the safe iterators pointing to the deleted element, i.e., when trying to dereference those iterators, an exception will be raised because they will know that the element they point to no longer exists.
| iter | An iterator over the element to remove. |
Definition at line 871 of file hashTable_tpl.h.
References _erase_().
| void gum::HashTable< Key, Val >::erase | ( | const K & | key | ) |
Heterogeneous lookup: erase() without string allocation (accepts string_view, const char*, etc.).
Definition at line 863 of file hashTable_tpl.h.
References _erase_(), _hash_func_, _nodes_, erase(), and key().
| void gum::HashTable< Key, Val >::erase | ( | const Key & | key | ) |
Removes a given element from the hash table.
The element is the first one encountered in the list (from begin() to end()) having the specified key. If no such element can be found, nothing is done (in particular, it does not throw any exception). The function never resizes the nodes vector (even if the resizing policy would enable to decrease this size). The method runs in average in time linear to the number of iterators pointing to the table if the automatic resizing policy is set (else it is in linear time in the number of elements of the hash table plus the number of iterators).
| key | The key of the element to remove. |
Definition at line 849 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
Referenced by gum::DAGCycleDetector::_delWeightedSet_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fillMaps_(), erase(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), and reset().
| void gum::HashTable< Key, Val >::eraseAllVal | ( | const Val & | val | ) |
Removes all the elements having a certain value from the hash table.
If no such element can be found, nothing is done (in particular, it does not throw any exception). The function never resizes the nodes vector (even if the resizing policy would enable to decrease this size). Comparisons between Val instances are performed through == operators.
| val | The value to remove. |
Definition at line 921 of file hashTable_tpl.h.
| void gum::HashTable< Key, Val >::eraseByVal | ( | const Val & | val | ) |
Removes a given element from the hash table.
The element is the first one encountered in the list (from begin() to end()) having the specified value. If no such element can be found, nothing is done (in particular, it does not throw any exception). The function never resizes the nodes vector (even if the resizing policy would enable to decrease this size). Comparisons between Val instances are performed through == operators. Logically, this method should have been named "erase", however, this would have prevented creating hash tables where both keys and vals have the same type. Hence we chose to add "ByVal" after erase to make a difference between erasing by key and erasing by val.
| val | The value to remove. |
Definition at line 881 of file hashTable_tpl.h.
| bool gum::HashTable< Key, Val >::exists | ( | const K & | key | ) | const |
Heterogeneous lookup: exists() without string allocation (accepts string_view, const char*, etc.).
Definition at line 599 of file hashTable_tpl.h.
References _hash_func_, _nodes_, exists(), and key().
| bool gum::HashTable< Key, Val >::exists | ( | const Key & | key | ) | const |
Checks whether there exists an element with a given key in the hashtable.
The method runs in average in constant time if the resizing policy is set.
| key | The key to test for existence. |
Definition at line 591 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
Referenced by gum::SetIteratorSafe< const gum::DiscreteVariable * >::SetIteratorSafe(), gum::DAGCycleDetector::_addWeightedSet_(), gum::DAGCycleDetector::_delWeightedSet_(), _insert_(), gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::StructuredPlaner< GUM_ELEMENT >::_recurArgMaxCopy_(), gum::StructuredPlaner< GUM_ELEMENT >::_recurExtractOptPol_(), gum::credal::CredalNet< GUM_SCALAR >::_sort_varType_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::graph::chainComponents(), gum::graph::connectedComponents(), gum::graph::directedPath(), gum::graph::directedUnorientedPath(), gum::learning::FCI::doDdpOrientation_(), exists(), gum::ASTsum< GUM_SCALAR >::fastToLatex(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::LeafAggregator::leavesMap(), gum::graph::mixedOrientedPath(), gum::graph::mixedUnorientedPath(), gum::Set< Key >::operator*=(), gum::Set< Key >::operator+(), gum::Set< Key >::operator-(), gum::MultiDimFunctionGraphProjector< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::project(), gum::graph::detail::reconstructPath(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::Tensor< GUM_SCALAR >::reorganize(), gum::EliminationSequenceStrategy::setGraph(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::toDot(), gum::CausalFormula< GUM_SCALAR >::toLatex(), and gum::graph::undirectedPath().
| HashTable< Key, Val >::mapped_type & gum::HashTable< Key, Val >::getWithDefault | ( | const Key & | key, |
| const Val & | default_value ) |
Returns a reference on the element the key of which is passed in argument.
In case of multiple identical keys in the hash table, the first value encountered is returned. The method runs in constant time. In case of not found key, (key,default_value) is inserted in *this.
| key | The key for which we want the value. |
| default_value | The default value to return if key does not match any value. |
Definition at line 796 of file hashTable_tpl.h.
References _hash_func_, _nodes_, insert(), key(), and gum::HashTableBucket< Key, Val >::val().
Referenced by gum::graph::_bayesBall_(), and gum::ASTtree< GUM_SCALAR >::_latexCorrect().
| HashTable< Key, Val >::mapped_type & gum::HashTable< Key, Val >::getWithDefault | ( | Key && | key, |
| Val && | default_value ) |
Returns a reference on the element the key of which is passed in argument.
In case of multiple identical keys in the hash table, the first value encountered is returned. The method runs in constant time. In case of not found key, (key,default_value) is inserted in *this.
| key | The key for which we want the value. |
| default_value | The default value to return if key does not match any value. |
Definition at line 805 of file hashTable_tpl.h.
| HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::insert | ( | const Key & | key, |
| const Val & | val ) |
Adds a new element (actually a copy of this element) into the hash table.
If there already exists an element with the same key in the table and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
| key | The key to add. |
| val | The value to add. |
Definition at line 754 of file hashTable_tpl.h.
References _insert_(), and gum::HashTableBucket< Key, Val >::elt().
Referenced by gum::learning::IBNLearner::Database::Database(), gum::learning::IBNLearner::Database::Database(), HashTable(), gum::prm::gspan::Pattern::Pattern(), gum::SetIteratorSafe< const gum::DiscreteVariable * >::SetIteratorSafe(), gum::DAGCycleDetector::_addWeightedSet_(), gum::MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_checkConditions_(), gum::DefaultJunctionTreeStrategy::_computeJunctionTree_(), gum::StaticTriangulation::_computeMaxPrimeJunctionTree_(), gum::StaticTriangulation::_computeRecursiveThinning_(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_fillCpf_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fillMaps_(), gum::MultiDimFunctionGraphOperator< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_ELEMENT, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromChild_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromParent_(), gum::Counterfactual< GUM_ELEMENT >::_idAssignToNameAssign_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::StructuredPlaner< GUM_ELEMENT >::_recurArgMaxCopy_(), gum::StructuredPlaner< GUM_ELEMENT >::_recurExtractOptPol_(), gum::DAGCycleDetector::_restrictWeightedSet_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_(), gum::credal::CredalNet< GUM_SCALAR >::_sort_varType_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::DAGCycleDetector::addArc(), gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenTensors(), gum::graph::chainComponents(), gum::CausalModel< GUM_ELEMENT >::children(), gum::SetIteratorSafe< const gum::DiscreteVariable * >::clear(), gum::ExactBNdistance< GUM_SCALAR >::computeKL_(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::MCBNDistance< GUM_SCALAR >::computeKL_(), gum::graph::connectedComponents(), gum::graph::directedPath(), gum::graph::directedUnorientedPath(), gum::DAGCycleDetector::eraseArc(), gum::ASTsum< GUM_SCALAR >::fastToLatex(), gum::MultiDimFunctionGraphGenerator::generate(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), getWithDefault(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::graph::hasUndirectedCycle(), gum::LeafAggregator::leavesMap(), map(), gum::graph::mixedOrientedPath(), gum::graph::mixedUnorientedPath(), gum::Set< Key >::operator+(), gum::Set< Key >::operator-(), gum::learning::Miic::orientationMiic_(), gum::MultiDimFunctionGraphProjector< GUM_ELEMENT, FUNCTOR, TerminalNodePolicy >::project(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::Tensor< GUM_SCALAR >::reorganize(), gum::learning::FCI::ruleR4_(), gum::prm::PRMClass< GUM_SCALAR >::scope(), gum::DAGCycleDetector::setDAG(), gum::learning::IBNLearner::setSliceOrder(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::toDot(), gum::CausalFormula< GUM_SCALAR >::toLatex(), gum::graph::topologicalOrder(), gum::graph::undirectedPath(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::insert | ( | const std::pair< Key, Val > & | elt | ) |
Adds a new element (actually a copy of this element) into the hash table.
If there already exists an element with the same key in the table and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
| elt | The pair of key value to add. |
Definition at line 771 of file hashTable_tpl.h.
References _insert_(), and gum::HashTableBucket< Key, Val >::elt().
| HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::insert | ( | Key && | key, |
| Val && | val ) |
Moves a new element in the hash table.
If there already exists an element with the same key in the table and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
| key | The key to move. |
| val | The value to move. |
Definition at line 762 of file hashTable_tpl.h.
| HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::insert | ( | std::pair< Key, Val > && | elt | ) |
Moves a new element in the hash table.
If there already exists an element with the same key in the table and the uniqueness policy prevents multiple identical keys to belong to the same hashtable, an exception DuplicateElement is thrown. If the uniqueness policy is not set, the method runs in the worst case in constant time, else if the automatic resizing policy is set, it runs in constant time in average linear in the number of elements by slot.
| DuplicateElement | is thrown when attempting to insert a pair (key,val) in a hash table containing already a pair with the same key and when the hash table's uniqueness policy is set. |
| elt | The pair of key value to move in this gum::HashTable. |
Definition at line 779 of file hashTable_tpl.h.
References _insert_(), and gum::HashTableBucket< Key, Val >::elt().
| const Key & gum::HashTable< Key, Val >::key | ( | const Key & | key | ) | const |
Returns a reference on a given key.
Some complex structures use pointers on keys of hashtables. These structures thus require that we do not only get a copy of a given key, but the key stored in the hashtable itself. This is the very purpose of this function.
| key | The key to return. |
| NotFound | Raised if the element cannot be found. |
Definition at line 903 of file hashTable_tpl.h.
References _hash_func_, _nodes_, GUM_ERROR, key(), and gum::HashTableBucket< Key, Val >::key().
Referenced by erase(), erase(), exists(), exists(), getWithDefault(), key(), operator[](), operator[](), operator[](), operator[](), reset(), set(), tryGet(), tryGet(), tryGet(), tryGet(), and tryGetKey().
| const Key & gum::HashTable< Key, Val >::keyByVal | ( | const Val & | val | ) | const |
Returns a reference on the key given a value.
In case of multiple identical values in the hash table, the first key encountered is returned. The method runs in linear time.
| val | The value for which the key is returned. |
| NotFound | Raised if the element cannot be found. |
Definition at line 895 of file hashTable_tpl.h.
References begin(), end(), and GUM_ERROR.
|
noexcept |
Returns the current checking policy.
Definition at line 656 of file hashTable_tpl.h.
References _key_uniqueness_policy_.
| HashTable< Key, Mount > gum::HashTable< Key, Val >::map | ( | const Mount & | val, |
| Size | size = Size(0), | ||
| bool | resize_pol = HashTableConst::default_resize_policy, | ||
| bool | key_uniqueness_pol = HashTableConst::default_uniqueness_policy ) const |
Creates a hashtable of mounts with a given value from a hashtable of vals.
| val | The value taken by all the elements of the resulting hashtable. |
| size | The size of the resulting hashtable. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions |
| resize_pol | the resizing policy (automatic or manual resizing) |
| key_uniqueness_pol | uniqueness policy |
Definition at line 1003 of file hashTable_tpl.h.
References HashTable(), and size().
| HashTable< Key, Mount > gum::HashTable< Key, Val >::map | ( | Mount(* | f )(const Val &), |
| Size | size = Size(0), | ||
| bool | resize_pol = HashTableConst::default_resize_policy, | ||
| bool | key_uniqueness_pol = HashTableConst::default_uniqueness_policy ) const |
Transforms a hashtable of vals into a hashtable of mountains.
| f | A function that maps any Val element into a Mount. |
| size | The size of the resulting hashtable. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions |
| resize_pol | the resizing policy (automatic or manual resizing) |
| key_uniqueness_pol | uniqueness policy |
Definition at line 980 of file hashTable_tpl.h.
References HashTable(), _nb_elements_, and size().
| HashTable< Key, Mount > gum::HashTable< Key, Val >::map | ( | Mount(* | f )(Val &), |
| Size | size = Size(0), | ||
| bool | resize_pol = HashTableConst::default_resize_policy, | ||
| bool | key_uniqueness_pol = HashTableConst::default_uniqueness_policy ) const |
Transforms a hashtable of vals into a hashtable of mountains.
| f | A function that maps any Val element into a Mount. |
| size | The size of the resulting hashtable. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions |
| resize_pol | the resizing policy (automatic or manual resizing) |
| key_uniqueness_pol | uniqueness policy |
Definition at line 957 of file hashTable_tpl.h.
References HashTable(), _nb_elements_, begin(), end(), and size().
| HashTable< Key, Mount > gum::HashTable< Key, Val >::map | ( | Mount(* | f )(Val), |
| Size | size = Size(0), | ||
| bool | resize_pol = HashTableConst::default_resize_policy, | ||
| bool | key_uniqueness_pol = HashTableConst::default_uniqueness_policy ) const |
Transforms a hashtable of vals into a hashtable of mountains.
| f | A function that maps any Val element into a Mount. |
| size | The size of the resulting hashtable. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions |
| resize_pol | the resizing policy (automatic or manual resizing) |
| key_uniqueness_pol | uniqueness policy |
Definition at line 934 of file hashTable_tpl.h.
References HashTable(), _nb_elements_, begin(), end(), insert(), and size().
| HashTable< Key, Val > & gum::HashTable< Key, Val >::operator= | ( | const HashTable< Key, Val > & | from | ) |
Copy operator.
The copy operators ensures that whenever a memory allocation problem occurs, no memory leak occurs as well and it also guarantees that in this case the hashtable returned is in a coherent state (it is an empty hashtable). Note that the copy not only involves copying pairs (key,value) but also the copy of the resize and key uniqueness policies.
| from | The gum::HashTable to copy. |
Definition at line 403 of file hashTable_tpl.h.
References HashTable().
|
noexcept |
Move operator.
| from | The gum::HashTable to move. |
Definition at line 437 of file hashTable_tpl.h.
References HashTable(), and _safe_iterators_.
| bool gum::HashTable< Key, Val >::operator== | ( | const HashTable< Key, Val > & | from | ) | const |
Checks whether two hashtables contain the same elements.
Two hashtables are considered equal if they contain the identical pairs (key,val). Two pairs are identical if their keys have the same hashed value, these two keys are equal in the sense of ==, and their val's are also equal in the sense of ==.
| from | The gum::HashTable to test for equality. |
Definition at line 1025 of file hashTable_tpl.h.
References HashTable(), _nb_elements_, begin(), end(), and tryGet().
| Val & gum::HashTable< Key, Val >::operator[] | ( | const K & | key | ) |
Heterogeneous lookup: operator[] without string allocation (accepts string_view, const char*, etc.).
Definition at line 562 of file hashTable_tpl.h.
References HashTable(), _hash_func_, _nodes_, GUM_ERROR, key(), and gum::HashTableBucket< Key, Val >::val().
| const Val & gum::HashTable< Key, Val >::operator[] | ( | const K & | key | ) | const |
Heterogeneous lookup: operator[] const without string allocation.
Definition at line 573 of file hashTable_tpl.h.
References HashTable(), _hash_func_, _nodes_, GUM_ERROR, key(), and gum::HashTableBucket< Key, Val >::pair.
| Val & gum::HashTable< Key, Val >::operator[] | ( | const Key & | key | ) |
Returns a reference on the value the key of which is passed in argument.
In case of multiple identical keys in the hash table, the first value encountered is returned. The method runs in constant time.
| key | The key of the value to return. |
| NotFound | exception is thrown if the element cannot be found. |
Definition at line 549 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
| const Val & gum::HashTable< Key, Val >::operator[] | ( | const Key & | key | ) | const |
returns a reference on the value the key of which is passed in argument
In case of multiple identical keys in the hash table, the first value encountered is returned. The method runs in constant time.
| NotFound | exception is thrown if the element cannot be found. |
Definition at line 554 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
| void gum::HashTable< Key, Val >::reset | ( | const Key & | key | ) |
Removes a property (i.e., remove an element).
Reset removes a property (i.e., a pair (key,val)) if it exists. This is an alias for erase but it is quite convenient when dealing with "dynamic property lists".
| key | The property to remove. |
Definition at line 890 of file hashTable_tpl.h.
References erase(), and key().
| void gum::HashTable< Key, Val >::resize | ( | Size | new_size | ) |
Changes the number of slots in the 'nodes' vector of the hash table.
Usually, method resize enables the user to resize manually the hashtable. When in automatic resize mode, the function will actually resize the table only if resizing policy is compatible with the new size, i.e., the new size is not so small that there would be too many elements per slot in the table (this would lead to a significant loss in performance). However, the resizing policy may be changed by using method setResizePolicy. The method runs in linear time in the size of the hashtable. Upon memory allocation problem, the fuction guarantees that no data is lost and that the hash table and its iterators are in a coherent state. In such a case, a bad_alloc exception is thrown.
| new_size | The new number of slots in the gum::HashTable. |
Definition at line 661 of file hashTable_tpl.h.
References _hash_func_, gum::_hashTableLog2_(), _nb_elements_, _resize_policy_, _size_, and gum::HashTableConst::default_mean_val_by_slot.
|
noexcept |
Returns the current resizing policy.
Definition at line 646 of file hashTable_tpl.h.
References _resize_policy_.
| void gum::HashTable< Key, Val >::set | ( | const Key & | key, |
| const Val & | default_value ) |
Add a new property or modify it if it already existed.
When used as a "dynamic property list", it may be convenient to use this function. Function set inserts a new pair (key,val) if the key does not already exists, or it changes the value associated with key if a pair (key,val) already exists in the hash table.
| key | The key of the value to add or set. |
| default_value | The value to set or add. |
Definition at line 813 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
Referenced by gum::learning::FCI::ruleR4_().
|
noexcept |
Enables the user to change dynamically the policy for checking whether there can exist several elements in the table with identical keys.
By default, we should always check that there does not exist duplicate keys. However, this test slows the insertion of elements in the table. So, when we know for sure that no duplicate key will be entered into the table, we may avoid uniqueness checks.
Definition at line 651 of file hashTable_tpl.h.
References _key_uniqueness_policy_.
|
noexcept |
Enables the user to change dynamically the resizing policy.
In most cases, this should be useless. However, when available memory becomes rare, avoiding automatic resizing may speed-up new insertions in the table.
| new_policy | The new resizing policy, true implies automatic resizing. |
Definition at line 641 of file hashTable_tpl.h.
References _resize_policy_.
|
noexcept |
Returns the number of elements stored into the hashtable.
The method runs in constant time.
Definition at line 581 of file hashTable_tpl.h.
References _nb_elements_.
Referenced by HashTable(), _create_(), map(), map(), map(), and map().
| optional_ref< Val > gum::HashTable< Key, Val >::tryGet | ( | const K & | key | ) |
Heterogeneous lookup: tryGet() without string allocation (accepts string_view, const char*, etc.).
Definition at line 622 of file hashTable_tpl.h.
References _hash_func_, _nodes_, key(), tryGet(), and gum::HashTableBucket< Key, Val >::val().
| optional_ref< const Val > gum::HashTable< Key, Val >::tryGet | ( | const K & | key | ) | const |
Heterogeneous lookup: tryGet() const without string allocation.
Definition at line 633 of file hashTable_tpl.h.
References _hash_func_, _nodes_, key(), gum::HashTableBucket< Key, Val >::pair, and tryGet().
| optional_ref< Val > gum::HashTable< Key, Val >::tryGet | ( | const Key & | key | ) |
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
This avoids the double lookup of exists() + operator[].
| key | The key to search for. |
Definition at line 605 of file hashTable_tpl.h.
References _hash_func_, _nodes_, key(), and gum::HashTableBucket< Key, Val >::val().
Referenced by gum::learning::IBNLearner::Database::Database(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromChild_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromParent_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_(), operator==(), gum::GraphicalModel::property(), tryGet(), and tryGet().
| optional_ref< const Val > gum::HashTable< Key, Val >::tryGet | ( | const Key & | key | ) | const |
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
This avoids the double lookup of exists() + operator[].
| key | The key to search for. |
Definition at line 612 of file hashTable_tpl.h.
References _hash_func_, _nodes_, key(), and gum::HashTableBucket< Key, Val >::pair.
| optional_ref< const Key > gum::HashTable< Key, Val >::tryGetKey | ( | const Key & | key | ) | const |
Returns an optional reference to a given key, or nullptr if the hash table does not contain it.
Some complex structures use pointers on keys of hashtables. These structures thus require that we do not only get a copy of a given key, but the key stored in the hashtable itself. This is the very purpose of this function.
| key | The key to return. |
| NotFound | Raised if the element cannot be found. |
Definition at line 913 of file hashTable_tpl.h.
References _hash_func_, _nodes_, key(), and gum::HashTableBucket< Key, Val >::key().
|
friend |
For bijections to quickly access data.
Definition at line 1522 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1501 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1501 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1501 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1501 of file hashTable.h.
|
friend |
Prints the content of a gum::HashTable with pointers key in the stream.
Definition at line 1091 of file hashTable_tpl.h.
|
friend |
Prints the content of a gum::HashTable in the stream.
Definition at line 1072 of file hashTable_tpl.h.
|
mutableprivate |
Returns where the begin index should be.
Beware: the beginning of a HashTable is the end of its nodes vector, i.e., the Bucket at the highest index in nodes. This enables a slightly faster parsing than if it were the lowest index.
Definition at line 1560 of file hashTable.h.
Referenced by HashTable().
|
private |
The function used to hash keys (may change when the table is resized).
Definition at line 1538 of file hashTable.h.
Referenced by _create_(), _insert_(), erase(), erase(), exists(), exists(), getWithDefault(), key(), operator[](), operator[](), operator[](), operator[](), resize(), set(), tryGet(), tryGet(), tryGet(), tryGet(), and tryGetKey().
|
private |
Shall we check for key uniqueness in the table?
Definition at line 1544 of file hashTable.h.
Referenced by HashTable(), HashTable(), _insert_(), keyUniquenessPolicy(), and setKeyUniquenessPolicy().
|
private |
Number of elements of type Val stored in the hash table.
Definition at line 1535 of file hashTable.h.
Referenced by _erase_(), begin(), begin(), beginSafe(), beginSafe(), cbegin(), cbeginSafe(), empty(), map(), map(), map(), operator==(), resize(), and size().
|
private |
The hash table is represented as a vector of chained lists.
' __nodes' is this very vector.
Definition at line 1529 of file hashTable.h.
Referenced by HashTable(), _create_(), _erase_(), _insert_(), clear(), erase(), erase(), exists(), exists(), getWithDefault(), key(), gum::HashTableList< Key, Val >::operator<<, gum::HashTableList< Key, Val >::operator<<, operator[](), operator[](), operator[](), operator[](), set(), tryGet(), tryGet(), tryGet(), tryGet(), and tryGetKey().
|
private |
Is resizing performed automatically?
Definition at line 1541 of file hashTable.h.
Referenced by HashTable(), HashTable(), resize(), resizePolicy(), and setResizePolicy().
|
mutableprivate |
The list of safe iterators pointing to the hash table.
Definition at line 1563 of file hashTable.h.
Referenced by _clearIterators_(), _erase_(), and operator=().
|
private |
The number of nodes in vector ' __nodes'.
Definition at line 1532 of file hashTable.h.
Referenced by HashTable(), HashTable(), HashTable(), HashTable(), _copy_(), capacity(), clear(), gum::HashTableList< Key, Val >::operator<<, gum::HashTableList< Key, Val >::operator<<, and resize().