30 #ifndef GUM_HASHTABLE_H 31 #define GUM_HASHTABLE_H 36 #include <initializer_list> 47 #ifndef DOXYGEN_SHOULD_SKIP_THIS 50 template <
typename Key,
typename Val,
typename Alloc >
52 template <
typename Key,
typename Val,
typename Alloc >
54 template <
typename Key,
typename Val >
55 class HashTableIterator;
56 template <
typename Key,
typename Val >
57 class HashTableConstIterator;
58 template <
typename Key,
typename Val >
59 class HashTableIteratorSafe;
60 template <
typename Key,
typename Val >
61 class HashTableConstIteratorSafe;
62 template <
typename T1,
typename T2,
typename Alloc >
119 template <
typename Key,
typename Val,
typename Alloc >
140 template <
typename Key,
typename Val,
typename Alloc >
158 template <
typename Key,
typename Val,
typename Alloc >
178 template <
typename Key,
typename Val,
typename Alloc >
201 template <
typename Key,
typename Val >
204 std::pair< const Key, Val >
pair;
261 template <
typename... Args >
264 pair(
std::forward< Args >(args)...) {}
275 std::pair< const Key, Val >&
elt() {
return pair; }
281 Key&
key() {
return const_cast< Key&
>(pair.first); }
287 Val&
val() {
return pair.second; }
304 template <
typename Key,
typename Val,
typename Alloc >
407 template < typename OtherAlloc >
409 operator=(const
HashTableList< Key, Val, OtherAlloc >& from);
469 bool exists(const
key_type& key) const;
477 void insert(
Bucket* new_elt) noexcept;
494 bool empty() const noexcept;
503 Bucket* bucket(const Key& key) const;
516 template < typename K, typename V, typename A >
523 friend
std::ostream& operator<<<>(
std::ostream&,
524 const HashTableList< Key, Val, Alloc >&);
525 friend
std::ostream& operator<<<>(
std::ostream&,
526 const HashTableList< Key*, Val, Alloc >&);
527 friend
std::ostream& operator<<<>(
std::ostream&,
529 friend
std::ostream& operator<<<>(
std::ostream&,
555 template <
typename OtherAlloc >
676 template <
typename Key,
678 typename Alloc = std::allocator< std::pair< Key, Val > > >
736 explicit HashTable(std::initializer_list< std::pair< Key, Val > > list);
764 template <
typename OtherAlloc >
979 static const
iterator& end4Statics();
1117 operator=(const
HashTable< Key, Val, Alloc >& from);
1131 template < typename OtherAlloc >
1133 operator=(const
HashTable< Key, Val, OtherAlloc >& from);
1154 Val& operator[](const Key& key);
1160 const Val& operator[](const Key& key) const;
1173 template < typename OtherAlloc >
1174 bool operator==(const
HashTable< Key, Val, OtherAlloc >& from) const;
1188 template < typename OtherAlloc >
1189 bool operator!=(const
HashTable< Key, Val, OtherAlloc >& from) const;
1206 Size capacity() const noexcept;
1226 void resize(
Size new_size);
1245 void setResizePolicy(const
bool new_policy) noexcept;
1251 bool resizePolicy() const noexcept;
1268 void setKeyUniquenessPolicy(const
bool new_policy) noexcept;
1274 bool keyUniquenessPolicy() const noexcept;
1289 Size size() const noexcept;
1301 bool exists(const Key& key) const;
1323 value_type& insert(const Key& key, const Val& val);
1401 template < typename... Args >
1418 mapped_type& getWithDefault(const Key& key, const Val& default_value);
1434 mapped_type& getWithDefault(Key&& key, Val&& default_value);
1447 void set(const Key& key, const Val& default_value);
1458 void reset(const Key& key);
1474 void erase(const Key& key);
1516 void eraseByVal(const Val& val);
1528 const Key& keyByVal(const Val& val) const;
1542 const Key& key(const Key& key) const;
1556 void eraseAllVal(const Val& val);
1572 bool empty() const noexcept;
1594 template < typename Mount,
1595 typename OtherAlloc = typename Alloc::template rebind<
1596 std::pair< Key, Mount > >::other >
1597 HashTable< Key, Mount, OtherAlloc > map(
1623 template < typename Mount,
1624 typename OtherAlloc = typename Alloc::template rebind<
1625 std::pair< Key, Mount > >::other >
1626 HashTable< Key, Mount, OtherAlloc > map(
1628 Size size = Size(0),
1652 template < typename Mount,
1653 typename OtherAlloc = typename Alloc::template rebind<
1654 std::pair< Key, Mount > >::other >
1655 HashTable< Key, Mount, OtherAlloc > map(
1656 Mount (*f)(const Val&),
1657 Size size = Size(0),
1683 template < typename Mount,
1684 typename OtherAlloc = typename Alloc::template rebind<
1685 std::pair< Key, Mount > >::other >
1686 HashTable< Key, Mount, OtherAlloc > map(
1688 Size size = Size(0),
1697 template < typename K, typename V, typename A >
1704 friend
std::ostream& operator<<<>(
std::ostream&,
1705 const HashTable< Key, Val, Alloc >&);
1706 friend
std::ostream& operator<<<>(
std::ostream& s,
1707 const HashTable< Key*, Val, Alloc >& table);
1710 template < typename T1, typename T2, typename A >
1730 bool __resize_policy{
true};
1733 bool __key_uniqueness_policy{
true};
1749 mutable Size __begin_index{std::numeric_limits< Size >::max()};
1752 mutable std::vector< HashTableConstIteratorSafe< Key, Val >* >
1783 template <
typename OtherAlloc >
1790 void __create(
Size size);
1795 void __clearIterators();
1813 void __insert(
Bucket* bucket);
1866 template <
typename Key,
typename Val,
typename Alloc >
1917 template <
typename Key,
typename Val >
1949 template <
typename Alloc >
1965 template <
typename Alloc >
2023 void clear() noexcept;
2122 template < typename K, typename V, typename A >
2126 const HashTable< Key, Val >* __table{
nullptr};
2156 Size __getIndex()
const noexcept;
2161 void __removeFromSafeList()
const;
2166 void __insertIntoSafeList()
const;
2219 template <
typename Key,
typename Val >
2250 template <
typename Alloc >
2265 template <
typename Alloc >
2464 template < typename Key, typename Val >
2488 HashTableConstIterator() noexcept;
2496 template < typename Alloc >
2497 HashTableConstIterator(const
HashTable< Key, Val, Alloc >& tab) noexcept;
2510 template < typename Alloc >
2511 HashTableConstIterator(const
HashTable< Key, Val, Alloc >& tab,
Size ind_elt);
2517 HashTableConstIterator(
2518 const HashTableConstIterator< Key, Val >& from) noexcept;
2524 HashTableConstIterator(HashTableConstIterator< Key, Val >&& from) noexcept;
2529 ~HashTableConstIterator() noexcept;
2565 void clear() noexcept;
2578 HashTableConstIterator< Key, Val >&
2579 operator=(const HashTableConstIterator< Key, Val >& from) noexcept;
2586 HashTableConstIterator< Key, Val >&
2587 operator=(HashTableConstIterator< Key, Val >&& from) noexcept;
2606 HashTableConstIterator< Key, Val >& operator++() noexcept;
2613 HashTableConstIterator< Key, Val >& operator+=(
Size i) noexcept;
2622 HashTableConstIterator< Key, Val > operator+(
Size i) const noexcept;
2630 bool operator!=(const HashTableConstIterator< Key, Val >& from) const noexcept;
2638 bool operator==(const HashTableConstIterator< Key, Val >& from) const noexcept;
2665 template < typename K, typename V, typename A >
2672 const HashTable< Key, Val >* __table{
nullptr};
2695 Size __getIndex()
const noexcept;
2749 template <
typename Key,
typename Val >
2781 template < typename Alloc >
2797 template < typename Alloc >
2939 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2940 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2941 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2942 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2948 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2949 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2950 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2951 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2957 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2958 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2959 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2960 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2966 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2967 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2968 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2969 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 2980 #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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.