![]() |
aGrUM 2.3.2
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 | |
| template<typename... Args> | |
| INLINE HashTable< Key, Val >::value_type & | emplace (Args &&... args) |
| template<typename Mount> | |
| HashTable< Key, Mount > INLINE | map (Mount(*f)(Val), Size size, bool resize_pol, bool key_uniqueness_pol) const |
| template<typename Mount> | |
| HashTable< Key, Mount > INLINE | map (Mount(*f)(Val &), Size size, bool resize_pol, bool key_uniqueness_pol) const |
| template<typename Mount> | |
| HashTable< Key, Mount > INLINE | map (Mount(*f)(const Val &), Size size, bool resize_pol, bool key_uniqueness_pol) const |
| template<typename Mount> | |
| HashTable< Key, Mount > INLINE | map (const Mount &val, Size size, bool resize_pol, bool key_uniqueness_pol) const |
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) | |
| 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) |
| 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 | |
| bool | operator== (const HashTable< Key, Val > &from) const |
| Checks whether two hashtables contain the same elements. | |
| bool | operator!= (const HashTable< Key, Val > &from) const |
| Checks whether two hashtables contain different sets of 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. | |
| 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. | |
| 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. | |
| 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 637 of file hashTable.h.
| using gum::HashTable< Key, Val >::Bucket = HashTableBucket< Key, Val > |
The buckets where data are stored.
Definition at line 657 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_iterator = HashTableConstIterator< Key, Val > |
Types for STL compliance.
Definition at line 651 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_iterator_safe = HashTableConstIteratorSafe< Key, Val > |
Types for STL compliance.
Definition at line 653 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_pointer = const value_type* |
Types for STL compliance.
Definition at line 647 of file hashTable.h.
| using gum::HashTable< Key, Val >::const_reference = const value_type& |
Types for STL compliance.
Definition at line 645 of file hashTable.h.
| using gum::HashTable< Key, Val >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 649 of file hashTable.h.
| using gum::HashTable< Key, Val >::iterator = HashTableIterator< Key, Val > |
Types for STL compliance.
Definition at line 650 of file hashTable.h.
| using gum::HashTable< Key, Val >::iterator_safe = HashTableIteratorSafe< Key, Val > |
Types for STL compliance.
Definition at line 652 of file hashTable.h.
| using gum::HashTable< Key, Val >::key_type = Key |
Types for STL compliance.
Definition at line 641 of file hashTable.h.
| using gum::HashTable< Key, Val >::mapped_type = Val |
Types for STL compliance.
Definition at line 642 of file hashTable.h.
| using gum::HashTable< Key, Val >::pointer = value_type* |
Types for STL compliance.
Definition at line 646 of file hashTable.h.
| using gum::HashTable< Key, Val >::reference = value_type& |
Types for STL compliance.
Definition at line 644 of file hashTable.h.
| using gum::HashTable< Key, Val >::size_type = Size |
Types for STL compliance.
Definition at line 648 of file hashTable.h.
| using gum::HashTable< Key, Val >::value_type = std::pair< const Key, Val > |
Types for STL compliance.
Definition at line 643 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 302 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_(), operator!=(), operator=(), operator=(), and operator==().
|
explicit |
Initializer list constructor.
| list | The initialized list. |
Definition at line 314 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 330 of file hashTable_tpl.h.
References HashTable(), _begin_index_, _copy_(), _create_(), _key_uniqueness_policy_, _resize_policy_, and _size_.
| gum::HashTable< Key, Val >::HashTable | ( | HashTable< Key, Val > && | from | ) |
Move constructor.
| from | The gum::HashTable to move. |
Definition at line 344 of file hashTable_tpl.h.
References HashTable(), _begin_index_, _hash_func_, _key_uniqueness_policy_, _nb_elements_, _nodes_, _resize_policy_, _safe_iterators_, and _size_.
| INLINE gum::HashTable< Key, Val >::~HashTable | ( | ) |
Class destructor.
Definition at line 376 of file hashTable_tpl.h.
References HashTable(), and _clearIterators_().
|
private |
Clear all the safe iterators.
Definition at line 355 of file hashTable_tpl.h.
References _safe_iterators_, and clear().
Referenced by ~HashTable().
|
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 267 of file hashTable_tpl.h.
References HashTable(), _nb_elements_, _nodes_, _size_, and clear().
Referenced by HashTable().
|
private |
Used by all default constructors (general and specialized).
| size | The size of the gum::HashTable to create. |
Definition at line 293 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 732 of file hashTable_tpl.h.
References _begin_index_, _nb_elements_, _nodes_, _safe_iterators_, and empty().
Referenced by erase(), erase(), and eraseByVal().
|
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 632 of file hashTable_tpl.h.
References _begin_index_, _hash_func_, _key_uniqueness_policy_, _nb_elements_, _nodes_, _resize_policy_, _size_, gum::HashTableConst::default_mean_val_by_slot, exists(), GUM_ERROR, gum::HashTableBucket< Key, Val >::key(), and resize().
Referenced by insert(), insert(), and insert().
| INLINE 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 464 of file hashTable_tpl.h.
Referenced by gum::MultiDimFunctionGraphOperator< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), keyByVal(), and gum::learning::SimpleMiic::orientationMiic_().
| INLINE 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 471 of file hashTable_tpl.h.
| INLINE 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 503 of file hashTable_tpl.h.
References _nb_elements_, and endSafe().
Referenced by gum::DAGCycleDetector::hasCycleFromModifications(), gum::LeafAggregator::leavesMap(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| INLINE 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 511 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 541 of file hashTable_tpl.h.
References _size_.
Referenced by gum::ArcGraphPart::ArcGraphPart().
| INLINE 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 478 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(), eraseByVal(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::Set< Key >::operator*(), and gum::Set< Key >::operator+().
| INLINE 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 519 of file hashTable_tpl.h.
References _nb_elements_, and cendSafe().
Referenced by gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), and gum::LeastSquareTestPolicy< GUM_SCALAR >::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 459 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(), eraseByVal(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::Set< Key >::operator*(), 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 498 of file hashTable_tpl.h.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::LeastSquareTestPolicy< GUM_SCALAR >::add(), cbeginSafe(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| INLINE 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 362 of file hashTable_tpl.h.
Referenced by _clearIterators_(), _copy_(), gum::MultiDimFunctionGraphOperator< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), and operator=().
| 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. |
| INLINE HashTable< Key, Val >::value_type & gum::HashTable< Key, Val >::emplace | ( | Args &&... | args | ) |
Definition at line 698 of file hashTable_tpl.h.
|
noexcept |
Indicates whether the hash table is empty.
Definition at line 820 of file hashTable_tpl.h.
References _nb_elements_.
Referenced by _erase_(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), 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 453 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 447 of file hashTable_tpl.h.
Referenced by gum::MultiDimFunctionGraphOperator< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), keyByVal(), 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 492 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 486 of file hashTable_tpl.h.
Referenced by beginSafe(), beginSafe(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::LeafAggregator::leavesMap(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| INLINE 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 776 of file hashTable_tpl.h.
References _erase_(), gum::HashTableConstIteratorSafe< Key, Val >::_getBucket_(), and gum::HashTableConstIteratorSafe< Key, Val >::_getIndex_().
| INLINE 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 771 of file hashTable_tpl.h.
References _erase_().
| INLINE 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 760 of file hashTable_tpl.h.
Referenced by gum::DAGCycleDetector::_delWeightedSet_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fillMaps_(), 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 813 of file hashTable_tpl.h.
| INLINE 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 781 of file hashTable_tpl.h.
References _erase_(), cbegin(), and cend().
| INLINE 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 546 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
Referenced by gum::DAGCycleDetector::_addWeightedSet_(), gum::DAGCycleDetector::_delWeightedSet_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromChild_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fromParent_(), _insert_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::_label_(), gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::StructuredPlaner< GUM_SCALAR >::_recurArgMaxCopy_(), gum::StructuredPlaner< GUM_SCALAR >::_recurExtractOptPol_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::MixedGraph::hasMixedOrientedPath(), gum::StructuredPlaner< double >::initialize(), gum::LeafAggregator::leavesMap(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::UndiGraph::nodes2ConnectedComponent(), gum::Set< Key >::operator*(), gum::Set< Key >::operator*=(), gum::Set< Key >::operator+(), gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::Tensor< GUM_SCALAR >::reorganize(), gum::BayesBall::requisiteNodes(), gum::EliminationSequenceStrategy::setGraph(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), gum::Set< const gum::Observation * >::toString(), and gum::EdgeGraphPart::undirectedPath().
| INLINE 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 wich we want the value. |
| default_value | The default value to return if key does not match any value. |
Definition at line 707 of file hashTable_tpl.h.
References _hash_func_, _nodes_, insert(), key(), and gum::HashTableBucket< Key, Val >::val().
| INLINE 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 wich we want the value. |
| default_value | The default value to return if key does not match any value. |
Definition at line 716 of file hashTable_tpl.h.
References _hash_func_, _nodes_, insert(), key(), and gum::HashTableBucket< Key, Val >::val().
| INLINE 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 665 of file hashTable_tpl.h.
References _insert_().
Referenced by gum::learning::IBNLearner::Database::Database(), gum::learning::IBNLearner::Database::Database(), HashTable(), gum::prm::gspan::Pattern::Pattern(), 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_SCALAR, FUNCTOR, TerminalNodePolicy >::_findRetrogradeVariables_(), gum::Regress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::_findRetrogradeVariables_(), 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::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_(), gum::StructuredPlaner< GUM_SCALAR >::_recurArgMaxCopy_(), gum::StructuredPlaner< GUM_SCALAR >::_recurExtractOptPol_(), gum::DAGCycleDetector::_restrictWeightedSet_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_(), 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::HashTable< const gum::DiscreteVariable *, Idx >::beginSafe(), gum::ExactBNdistance< GUM_SCALAR >::computeKL_(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::DAGCycleDetector::eraseArc(), gum::MultiDimFunctionGraphGenerator::generate(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), getWithDefault(), getWithDefault(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::Set< Key >::hashMap(), gum::MixedGraph::hasMixedOrientedPath(), gum::StructuredPlaner< double >::initialize(), gum::LeafAggregator::leavesMap(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::UndiGraph::nodes2ConnectedComponent(), gum::Set< Key >::operator*(), gum::Set< Key >::operator+(), gum::HashTable< const gum::DiscreteVariable *, Idx >::operator=(), gum::learning::Miic::orientationMiic_(), gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::Tensor< GUM_SCALAR >::reorganize(), gum::BayesBall::requisiteNodes(), gum::prm::PRMClass< GUM_SCALAR >::scope(), set(), gum::DAGCycleDetector::setDAG(), gum::learning::IBNLearner::setSliceOrder(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), gum::EdgeGraphPart::undirectedPath(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().
| INLINE 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 681 of file hashTable_tpl.h.
| INLINE 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 672 of file hashTable_tpl.h.
References _insert_().
| INLINE 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 689 of file hashTable_tpl.h.
References _insert_().
| INLINE 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 803 of file hashTable_tpl.h.
References _hash_func_, _nodes_, GUM_ERROR, key(), and gum::HashTableBucket< Key, Val >::key().
Referenced by exists(), getWithDefault(), getWithDefault(), key(), operator[](), operator[](), reset(), and set().
| INLINE 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 795 of file hashTable_tpl.h.
References begin(), end(), and GUM_ERROR.
|
noexcept |
Returns the current checking policy.
Definition at line 566 of file hashTable_tpl.h.
References _key_uniqueness_policy_.
| HashTable< Key, Mount > INLINE gum::HashTable< Key, Val >::map | ( | const Mount & | val, |
| Size | size, | ||
| bool | resize_pol, | ||
| bool | key_uniqueness_pol ) const |
Definition at line 895 of file hashTable_tpl.h.
| 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 |
| HashTable< Key, Mount > INLINE gum::HashTable< Key, Val >::map | ( | Mount(* | f )(const Val &), |
| Size | size, | ||
| bool | resize_pol, | ||
| bool | key_uniqueness_pol ) const |
Definition at line 872 of file hashTable_tpl.h.
| 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 |
| HashTable< Key, Mount > INLINE gum::HashTable< Key, Val >::map | ( | Mount(* | f )(Val &), |
| Size | size, | ||
| bool | resize_pol, | ||
| bool | key_uniqueness_pol ) const |
Definition at line 849 of file hashTable_tpl.h.
| 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 |
| HashTable< Key, Mount > INLINE gum::HashTable< Key, Val >::map | ( | Mount(* | f )(Val), |
| Size | size, | ||
| bool | resize_pol, | ||
| bool | key_uniqueness_pol ) const |
Definition at line 826 of file hashTable_tpl.h.
| 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 |
| INLINE bool gum::HashTable< Key, Val >::operator!= | ( | const HashTable< Key, Val > & | from | ) | const |
Checks whether two hashtables contain different sets of elements.
Two hashtables are considered different if they contain different pairs (key,val). Two pairs are different if their keys have different hashed values, or if they are different in the sense of !=, or if their val's are different in the sense of !=.
| from | The gum::HashTable to test for inequality. |
Definition at line 932 of file hashTable_tpl.h.
References HashTable(), and gum::operator==().
| 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 386 of file hashTable_tpl.h.
References HashTable().
| HashTable< Key, Val > & gum::HashTable< Key, Val >::operator= | ( | HashTable< Key, Val > && | from | ) |
Move operator.
| from | The gum::HashTable to move. |
Definition at line 420 of file hashTable_tpl.h.
References HashTable(), and clear().
| 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 917 of file hashTable_tpl.h.
References HashTable().
| INLINE 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 526 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
| INLINE 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 531 of file hashTable_tpl.h.
References _hash_func_, _nodes_, and key().
| INLINE 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 790 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 571 of file hashTable_tpl.h.
References _begin_index_, _hash_func_, gum::_hashTableLog2_(), _nb_elements_, _nodes_, _resize_policy_, _safe_iterators_, _size_, gum::HashTableConst::default_mean_val_by_slot, gum::HashTableBucket< Key, Val >::key(), and gum::HashTableBucket< Key, Val >::next.
Referenced by _insert_().
|
noexcept |
Returns the current resizing policy.
Definition at line 556 of file hashTable_tpl.h.
References _resize_policy_.
| INLINE 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 724 of file hashTable_tpl.h.
References _hash_func_, _nodes_, insert(), key(), and gum::HashTableBucket< Key, Val >::val().
|
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 561 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 551 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 536 of file hashTable_tpl.h.
References _nb_elements_.
Referenced by HashTable(), _create_(), and gum::Set< Key >::operator*().
|
friend |
For bijections to quickly access data.
Definition at line 1462 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1441 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1441 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1441 of file hashTable.h.
|
friend |
Friends to optimize the access to data, iterators must be friends.
Definition at line 1441 of file hashTable.h.
|
friend |
Prints the content of a gum::HashTable with pointers key in the stream.
Definition at line 990 of file hashTable_tpl.h.
|
friend |
Prints the content of a gum::HashTable in the stream.
Definition at line 971 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 1500 of file hashTable.h.
Referenced by HashTable(), HashTable(), _erase_(), _insert_(), and resize().
|
private |
The function used to hash keys (may change when the table is resized).
Definition at line 1478 of file hashTable.h.
Referenced by HashTable(), _create_(), _insert_(), exists(), getWithDefault(), getWithDefault(), key(), operator[](), operator[](), resize(), and set().
|
private |
Shall we check for key uniqueness in the table?
Definition at line 1484 of file hashTable.h.
Referenced by HashTable(), HashTable(), HashTable(), _insert_(), keyUniquenessPolicy(), and setKeyUniquenessPolicy().
|
private |
Number of elements of type Val stored in the hash table.
Definition at line 1475 of file hashTable.h.
Referenced by HashTable(), _copy_(), _erase_(), _insert_(), beginSafe(), beginSafe(), cbegin(), cbeginSafe(), empty(), resize(), and size().
|
private |
The hash table is represented as a vector of chained lists.
' __nodes' is this very vector.
Definition at line 1469 of file hashTable.h.
Referenced by HashTable(), _copy_(), _create_(), _erase_(), _insert_(), exists(), getWithDefault(), getWithDefault(), key(), gum::HashTableList< Key, Val >::operator<<, gum::HashTableList< Key, Val >::operator<<, operator[](), operator[](), resize(), and set().
|
private |
Is resizing performed automatically?
Definition at line 1481 of file hashTable.h.
Referenced by HashTable(), HashTable(), HashTable(), _insert_(), resize(), resizePolicy(), and setResizePolicy().
|
mutableprivate |
The list of safe iterators pointing to the hash table.
Definition at line 1503 of file hashTable.h.
Referenced by HashTable(), _clearIterators_(), _erase_(), and resize().
|
private |
The number of nodes in vector ' __nodes'.
Definition at line 1472 of file hashTable.h.
Referenced by HashTable(), HashTable(), HashTable(), HashTable(), _copy_(), _insert_(), capacity(), gum::HashTableList< Key, Val >::operator<<, gum::HashTableList< Key, Val >::operator<<, and resize().