9#ifndef MCRL2_UTILITIES_UNORDERED_SET_H
10#define MCRL2_UTILITIES_UNORDERED_SET_H
36 typename Hash = std::hash<Key>,
37 typename KeyEqual = std::equal_to<Key>,
38 typename Allocator = std::allocator<Key>,
39 bool ThreadSafe =
false,
46 template <
typename...>
using void_t = void;
48 template <
typename X,
typename =
void>
struct is_transparent : std::false_type
69 typename Hash = std::hash<Key>,
70 typename Equals = std::equal_to<Key>,
71 typename Allocator = std::allocator<Key>,
72 bool ThreadSafe =
false,
76 static_assert (!(ThreadSafe && Resize),
"ThreadSafe cannot be enabled together with automatic resizing.");
85 template<
typename Key_,
typename T,
typename Hash_,
typename KeyEqual,
typename Allocator_,
bool ThreadSafe_,
bool Resize_>
90 template<
typename Bucket,
bool Constant>
96 template<
typename Key_,
typename T,
typename Hash_,
typename KeyEqual,
typename Allocator_,
bool ThreadSafe_,
bool Resize_>
99 using bucket_it =
typename std::vector<Bucket>::const_iterator;
104 using reference =
typename std::conditional<Constant, const Key&, Key&>::type;
105 using pointer =
typename std::conditional<Constant, const Key*, Key*>::type;
138 return const_cast<pointer>(&(*m_key_it));
148 return !(*
this != other);
222 using pointer =
typename std::allocator_traits<Allocator>::pointer;
223 using const_pointer =
typename std::allocator_traits<Allocator>::const_pointer;
286 template<
typename ...Args>
287 std::pair<iterator, bool>
emplace(Args&&... args);
290 template<
typename...Args>
298 template<
typename ...Args>
303 template<
typename...Args>
306 template<
typename...Args>
348 template<
typename Key_,
typename T,
typename Hash_,
typename KeyEqual,
typename Allocator_,
bool ThreadSafe_,
bool Resize_>
353 template<
typename ...Args>
357 template<
typename ...Args>
361 template<
typename ...Args>
365 template<
typename ...Args>
388template<
typename Key,
389 typename Hash = std::hash<Key>,
390 typename Equals = std::equal_to<Key>,
392 bool ThreadSafe =
false>
The block allocator provides the allocator interface for the memory pool class. As such is can be use...
This essentially implements the std::forward_list, with the difference that it does not own the nodes...
key_iterator< true > const_iterator
typename std::allocator_traits< Allocator >::template rebind_alloc< Bucket::node > NodeAllocator
Rebind the passed to allocator to a bucket list node allocator.
A class for a map of keys to values in T based using the simple hash table set implementation.
An iterator over all elements in the unordered set.
unordered_set_iterator()=default
unordered_set_iterator(bucket_it it, bucket_it end, key_it_type before_it, key_it_type key)
Construct an iterator over all keys passed in this bucket and all remaining buckets.
key_it_type m_key_before_it
void goto_next_bucket()
Iterate to the next non-empty bucket.
typename Bucket::const_iterator key_it_type
unordered_set_iterator & operator++()
typename std::vector< Bucket >::const_iterator bucket_it
typename std::conditional< Constant, const Key *, Key * >::type pointer
std::forward_iterator_tag iterator_category
bucket_it & get_bucket_it()
unordered_set_iterator(bucket_it it)
Construct the end iterator.
pointer operator->() const
unordered_set_iterator(bucket_it it, bucket_it end)
Construct the begin iterator (over all elements).
bool operator==(const unordered_set_iterator &other) const
reference operator*() const
bool operator!=(const unordered_set_iterator &other) const
typename std::conditional< Constant, const Key &, Key & >::type reference
unordered_set_iterator operator++(int)
std::ptrdiff_t difference_type
key_it_type & key_before_it()
A unordered_set with a subset of the interface of std::unordered_set that only stores a single pointe...
std::vector< std::mutex > m_bucket_mutexes
const_local_iterator cbegin(size_type n) const
const_local_iterator end(size_type n) const
void erase(const Args &... args)
Erases the given key_type(args...) from the unordered set.
typename bucket_type::const_iterator local_iterator
std::ptrdiff_t difference_type
const_iterator find_impl(size_type bucket_index, const Args &... args) const
Searches for the element in the given bucket.
const value_type & const_reference
const_local_iterator begin(size_type n) const
size_type count(const Args &... args) const
Counts the number of occurrences of the given key (1 when it exists and 0 otherwise).
float max_load_factor() const
typename std::allocator_traits< Allocator >::pointer pointer
size_type find_bucket_index(const Args &... args) const
std::vector< bucket_type > m_buckets
std::pair< iterator, bool > emplace_impl(size_type bucket_index, Args &&... args)
Inserts T(args...) into the given bucket, assumes that it did not exists before. \threadsafe.
const_iterator cend() const
size_type bucket_count() const noexcept
bool empty() const noexcept
void erase_impl(const Args &... args)
Removes T(args...) from the set.
const_iterator begin() const
static constexpr bool allow_transparent
True iff the hash and equals functions allow transparent lookup,.
const_iterator end() const
typename std::vector< bucket_type >::iterator bucket_iterator
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > m_buckets_mask
Always equal to m_buckets.size() - 1.
size_type max_bucket_count() const noexcept
typename bucket_type::const_iterator const_local_iterator
typename std::allocator_traits< Allocator >::const_pointer const_pointer
allocator_type & get_allocator() noexcept
std::pair< iterator, bool > emplace(Args &&... args)
Inserts an element Key(args...) into the set if it did not already exist.
void rehash_if_needed()
Resizes the hash table if necessary.
allocator_type m_allocator
iterator find(const Args &... args)
const_iterator cbegin() const
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > m_number_of_elements
The number of elements stored in this set.
unordered_set_iterator< bucket_type, true > const_iterator
size_type size() const noexcept
typename std::vector< bucket_type >::const_iterator const_bucket_iterator
void clear()
Removes all elements from the set.
unordered_set(const unordered_set &set)
iterator erase(const_iterator it)
Erases the element pointed to by the iterator.
typename bucket_type::NodeAllocator allocator_type
size_type max_size() const noexcept
void max_load_factor(float factor)
size_type bucket(const key_type &key) const noexcept
hasher hash_function() const
size_type capacity() const noexcept
local_iterator end(size_type n)
unordered_set(unordered_set &&other)=default
const_local_iterator cend(size_type n) const
const_iterator find(const Args &... args) const
Searches whether an object key_type(args...) occurs in the set.
void rehash(size_type number_of_buckets)
Resize the number buckets to at least number_of_buckets.
unordered_set & operator=(const unordered_set &set)
local_iterator begin(size_type n)
size_type bucket_size(size_type n) const noexcept
unordered_set(size_type bucket_count, const hasher &hash=hasher(), const key_equal &equals=key_equal())
Constructs an unordered_set that contains bucket_count number of buckets.
unordered_set & operator=(unordered_set &&other)=default
const allocator_type & get_allocator() const noexcept
float load_factor() const
void reserve(size_type count)
Resizes the set to the given number of elements.
static constexpr Sentinel EndIterator
A end of the iterator sentinel.
static constexpr long BucketsPerMutex
Number of buckets per mutex.
static constexpr bool EnableLockfreeInsertion
Enables lockfree implementation of emplace.
void print_performance_statistics(const T &unordered_set)
Prints various information for unordered_set like data structures.