27 #ifndef GUM_HASHTABLE_H 28 #define GUM_HASHTABLE_H 33 #include <initializer_list> 44 #ifndef DOXYGEN_SHOULD_SKIP_THIS 47 template <
typename Key,
typename Val,
typename Alloc >
49 template <
typename Key,
typename Val,
typename Alloc >
51 template <
typename Key,
typename Val >
52 class HashTableIterator;
53 template <
typename Key,
typename Val >
54 class HashTableConstIterator;
55 template <
typename Key,
typename Val >
56 class HashTableIteratorSafe;
57 template <
typename Key,
typename Val >
58 class HashTableConstIteratorSafe;
59 template <
typename T1,
typename T2,
typename Alloc >
116 template <
typename Key,
typename Val,
typename Alloc >
137 template <
typename Key,
typename Val,
typename Alloc >
155 template <
typename Key,
typename Val,
typename Alloc >
175 template <
typename Key,
typename Val,
typename Alloc >
198 template <
typename Key,
typename Val >
201 std::pair< const Key, Val >
pair;
258 template <
typename... Args >
261 pair(
std::forward< Args >(args)...) {}
272 std::pair< const Key, Val >&
elt() {
return pair; }
278 Key&
key() {
return const_cast< Key&
>(pair.first); }
284 Val&
val() {
return pair.second; }
301 template <
typename Key,
typename Val,
typename Alloc >
404 template < typename OtherAlloc >
406 operator=(const
HashTableList< Key, Val, OtherAlloc >& from);
466 bool exists(const
key_type& key) const;
474 void insert(
Bucket* new_elt) noexcept;
491 bool empty() const noexcept;
500 Bucket* bucket(const Key& key) const;
513 template < typename K, typename V, typename A >
520 friend
std::ostream& operator<<<>(
std::ostream&,
521 const HashTableList< Key, Val, Alloc >&);
522 friend
std::ostream& operator<<<>(
std::ostream&,
523 const HashTableList< Key*, Val, Alloc >&);
524 friend
std::ostream& operator<<<>(
std::ostream&,
526 friend
std::ostream& operator<<<>(
std::ostream&,
552 template <
typename OtherAlloc >
673 template <
typename Key,
675 typename Alloc = std::allocator< std::pair< Key, Val > > >
733 explicit HashTable(std::initializer_list< std::pair< Key, Val > > list);
761 template <
typename OtherAlloc >
976 static const
iterator& end4Statics();
1114 operator=(const
HashTable< Key, Val, Alloc >& from);
1128 template < typename OtherAlloc >
1130 operator=(const
HashTable< Key, Val, OtherAlloc >& from);
1151 Val& operator[](const Key& key);
1157 const Val& operator[](const Key& key) const;
1170 template < typename OtherAlloc >
1171 bool operator==(const
HashTable< Key, Val, OtherAlloc >& from) const;
1185 template < typename OtherAlloc >
1186 bool operator!=(const
HashTable< Key, Val, OtherAlloc >& from) const;
1203 Size capacity() const noexcept;
1223 void resize(
Size new_size);
1242 void setResizePolicy(const
bool new_policy) noexcept;
1248 bool resizePolicy() const noexcept;
1265 void setKeyUniquenessPolicy(const
bool new_policy) noexcept;
1271 bool keyUniquenessPolicy() const noexcept;
1286 Size size() const noexcept;
1298 bool exists(const Key& key) const;
1320 value_type& insert(const Key& key, const Val& val);
1398 template < typename... Args >
1415 mapped_type& getWithDefault(const Key& key, const Val& default_value);
1431 mapped_type& getWithDefault(Key&& key, Val&& default_value);
1444 void set(const Key& key, const Val& default_value);
1455 void reset(const Key& key);
1471 void erase(const Key& key);
1513 void eraseByVal(const Val& val);
1525 const Key& keyByVal(const Val& val) const;
1539 const Key& key(const Key& key) const;
1553 void eraseAllVal(const Val& val);
1569 bool empty() const noexcept;
1591 template < typename Mount,
1592 typename OtherAlloc = typename Alloc::template rebind<
1593 std::pair< Key, Mount > >::other >
1594 HashTable< Key, Mount, OtherAlloc > map(
1620 template < typename Mount,
1621 typename OtherAlloc = typename Alloc::template rebind<
1622 std::pair< Key, Mount > >::other >
1623 HashTable< Key, Mount, OtherAlloc > map(
1625 Size size = Size(0),
1649 template < typename Mount,
1650 typename OtherAlloc = typename Alloc::template rebind<
1651 std::pair< Key, Mount > >::other >
1652 HashTable< Key, Mount, OtherAlloc > map(
1653 Mount (*f)(const Val&),
1654 Size size = Size(0),
1680 template < typename Mount,
1681 typename OtherAlloc = typename Alloc::template rebind<
1682 std::pair< Key, Mount > >::other >
1683 HashTable< Key, Mount, OtherAlloc > map(
1685 Size size = Size(0),
1694 template < typename K, typename V, typename A >
1701 friend
std::ostream& operator<<<>(
std::ostream&,
1702 const HashTable< Key, Val, Alloc >&);
1703 friend
std::ostream& operator<<<>(
std::ostream& s,
1704 const HashTable< Key*, Val, Alloc >& table);
1707 template < typename T1, typename T2, typename A >
1727 bool __resize_policy{
true};
1730 bool __key_uniqueness_policy{
true};
1746 mutable Size __begin_index{std::numeric_limits< Size >::max()};
1749 mutable std::vector< HashTableConstIteratorSafe< Key, Val >* >
1780 template <
typename OtherAlloc >
1787 void __create(
Size size);
1792 void __clearIterators();
1810 void __insert(
Bucket* bucket);
1863 template <
typename Key,
typename Val,
typename Alloc >
1914 template <
typename Key,
typename Val >
1946 template <
typename Alloc >
1962 template <
typename Alloc >
2020 void clear() noexcept;
2119 template < typename K, typename V, typename A >
2123 const HashTable< Key, Val >* __table{
nullptr};
2153 Size __getIndex()
const noexcept;
2158 void __removeFromSafeList()
const;
2163 void __insertIntoSafeList()
const;
2216 template <
typename Key,
typename Val >
2247 template <
typename Alloc >
2262 template <
typename Alloc >
2461 template < typename Key, typename Val >
2485 HashTableConstIterator() noexcept;
2493 template < typename Alloc >
2494 HashTableConstIterator(const
HashTable< Key, Val, Alloc >& tab) noexcept;
2507 template < typename Alloc >
2508 HashTableConstIterator(const
HashTable< Key, Val, Alloc >& tab,
Size ind_elt);
2514 HashTableConstIterator(
2515 const HashTableConstIterator< Key, Val >& from) noexcept;
2521 HashTableConstIterator(HashTableConstIterator< Key, Val >&& from) noexcept;
2526 ~HashTableConstIterator() noexcept;
2562 void clear() noexcept;
2575 HashTableConstIterator< Key, Val >&
2576 operator=(const HashTableConstIterator< Key, Val >& from) noexcept;
2583 HashTableConstIterator< Key, Val >&
2584 operator=(HashTableConstIterator< Key, Val >&& from) noexcept;
2603 HashTableConstIterator< Key, Val >& operator++() noexcept;
2610 HashTableConstIterator< Key, Val >& operator+=(
Size i) noexcept;
2619 HashTableConstIterator< Key, Val > operator+(
Size i) const noexcept;
2627 bool operator!=(const HashTableConstIterator< Key, Val >& from) const noexcept;
2635 bool operator==(const HashTableConstIterator< Key, Val >& from) const noexcept;
2662 template < typename K, typename V, typename A >
2669 const HashTable< Key, Val >* __table{
nullptr};
2692 Size __getIndex()
const noexcept;
2746 template <
typename Key,
typename Val >
2778 template < typename Alloc >
2794 template < typename Alloc >
2936 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2937 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2938 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2939 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2945 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2946 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2947 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2948 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2954 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2955 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2956 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2957 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2963 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2964 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2965 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2966 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2977 #endif // GUM_HASHTABLE_H const value_type & const_reference
Key & key()
Returns the key part of the pair.
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
const value_type * const_pointer
HashTableBucket()
Class constructor.
std::ptrdiff_t difference_type
Val key_type
types for STL compliance
typename IndexAllocator ::template rebind< Bucket >::other BucketAllocator
The Bucket allocator.
const value_type * const_pointer
A recipient for a pair of key value in a gum::HashTableList.
static constexpr Size default_mean_val_by_slot
The average number of elements admissible by slots.
BucketAllocator __alloc
The allocator for the buckets.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
HashTableBucket(const std::pair< const Key, Val > &p)
Constructor.
HashFunc< Key > __hash_func
The function used to hash keys (may change when the table is resized).
Emplace
A dummy type for the emplace constructor.
Safe Const Iterators for hashtables.
static constexpr Size default_size
The default number of slots in hashtables.
Classes providing basic hash functions for hash tables.
static const HashTableIterator< int, int > * __HashTableIterEnd
The unsafe iterator used by everyone.
const value_type * const_pointer
Base class for discrete random variable.
Safe Iterators for hashtables.
gum is the global namespace for all aGrUM entities
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
std::vector< HashTableConstIteratorSafe< Key, Val > *> __safe_iterators
The list of safe iterators pointing to the hash table.
The class for generic Hash Tables.
std::pair< const Val, Size > value_type
const value_type * const_pointer
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
static const HashTableIteratorSafe< int, int > * __HashTableIterEndSafe
The safe iterator used by everyone.
const value_type & const_reference
Implementation of the HashTable.
Val key_type
Types for STL compliance.
HashTableBucket(std::pair< const Key, Val > &&p)
Constructor.
std::pair< const const gum::DiscreteVariable *, Idx > value_type
static constexpr bool default_resize_policy
A Boolean indicating whether inserting too many values into the hashtable makes it resize itself auto...
std::pair< const Key, Val > pair
The pair stored in this bucket.
std::ptrdiff_t difference_type
Parameters specifying the default behavior of the hashtables.
std::forward_iterator_tag iterator_category
Types for STL compliance.
Set of pairs of elements with fast search for both elements.
std::forward_iterator_tag iterator_category
Types for STL compliance.
HashTableBucket(Emplace e, Args &&... args)
The emplace constructor.
A class used to create the static iterator used by HashTables.
HashTableBucket(const Key &k, const Val &v)
Constructor.
Val & val()
Returns the value part of the pair.
const value_type & const_reference
std::pair< const Val, Size > value_type
std::pair< const Key, bool > value_type
static constexpr bool default_uniqueness_policy
A Boolean indicating the default behavior when trying to insert more than once elements with identica...
std::ptrdiff_t difference_type
~HashTableBucket()
Class destructor.
const value_type & const_reference
A chained list used by gum::HashTable.
IndexAllocator allocator_type
HashTableBucket(Key &&k, Val &&v)
Constructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
IndexAllocator allocator_type
typename IndexAllocator ::template rebind< Bucket >::other BucketAllocator
The Bucket allocator.
HashTableBucket(const HashTableBucket< Key, Val > &from)
Copy constructor.
std::pair< const Key, Val > & elt()
Returns the pair stored in this bucket.