mCRL2
|
A unordered_set with a subset of the interface of std::unordered_set that only stores a single pointer for each element. More...
#include <unordered_set.h>
Classes | |
class | unordered_set_iterator |
An iterator over all elements in the unordered set. More... | |
Public Types | |
using | key_type = Key |
using | value_type = Key |
using | hasher = Hash |
using | key_equal = Equals |
using | allocator_type = typename bucket_type::NodeAllocator |
using | reference = value_type & |
using | const_reference = const value_type & |
using | pointer = typename std::allocator_traits< Allocator >::pointer |
using | const_pointer = typename std::allocator_traits< Allocator >::const_pointer |
using | const_local_iterator = typename bucket_type::const_iterator |
using | local_iterator = typename bucket_type::const_iterator |
using | const_iterator = unordered_set_iterator< bucket_type, true > |
using | iterator = const_iterator |
using | size_type = std::size_t |
using | difference_type = std::ptrdiff_t |
Public Member Functions | |
unordered_set () | |
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 (const unordered_set &set) | |
unordered_set & | operator= (const unordered_set &set) |
unordered_set (unordered_set &&other)=default | |
unordered_set & | operator= (unordered_set &&other)=default |
~unordered_set () | |
const allocator_type & | get_allocator () const noexcept |
allocator_type & | get_allocator () noexcept |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
bool | empty () const noexcept |
size_type | size () const noexcept |
size_type | max_size () const noexcept |
void | clear () |
Removes all elements from the set. | |
template<typename ... Args> | |
std::pair< iterator, bool > | emplace (Args &&... args) |
Inserts an element Key(args...) into the set if it did not already exist. | |
template<typename... Args> | |
void | erase (const Args &... args) |
Erases the given key_type(args...) from the unordered set. | |
iterator | erase (const_iterator it) |
Erases the element pointed to by the iterator. | |
template<typename ... Args> | |
size_type | count (const Args &... args) const |
Counts the number of occurrences of the given key (1 when it exists and 0 otherwise). | |
template<typename... Args> | |
const_iterator | find (const Args &... args) const |
Searches whether an object key_type(args...) occurs in the set. | |
template<typename... Args> | |
iterator | find (const Args &... args) |
local_iterator | begin (size_type n) |
local_iterator | end (size_type n) |
const_local_iterator | begin (size_type n) const |
const_local_iterator | end (size_type n) const |
const_local_iterator | cbegin (size_type n) const |
const_local_iterator | cend (size_type n) const |
size_type | bucket_count () const noexcept |
size_type | max_bucket_count () const noexcept |
size_type | bucket_size (size_type n) const noexcept |
size_type | bucket (const key_type &key) const noexcept |
float | load_factor () const |
float | max_load_factor () const |
void | max_load_factor (float factor) |
void | rehash (size_type number_of_buckets) |
Resize the number buckets to at least number_of_buckets. | |
void | reserve (size_type count) |
Resizes the set to the given number of elements. | |
hasher | hash_function () const |
key_equal | key_eq () const |
size_type | capacity () const noexcept |
void | rehash_if_needed () |
Resizes the hash table if necessary. | |
Private Types | |
using | bucket_type = detail::bucket_list< Key, Allocator > |
Combine the bucket list and a lock that locks modifications to the bucket list. | |
using | bucket_iterator = typename std::vector< bucket_type >::iterator |
using | const_bucket_iterator = typename std::vector< bucket_type >::const_iterator |
using | mutex_type = std::mutex |
Private Member Functions | |
template<typename ... Args> | |
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. | |
template<typename ... Args> | |
void | erase_impl (const Args &... args) |
Removes T(args...) from the set. | |
template<typename ... Args> | |
size_type | find_bucket_index (const Args &... args) const |
template<typename ... Args> | |
const_iterator | find_impl (size_type bucket_index, const Args &... args) const |
Searches for the element in the given bucket. | |
Private Attributes | |
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > | m_number_of_elements = 0 |
The number of elements stored in this set. | |
std::conditional_t< ThreadSafe, std::atomic< size_type >, size_type > | m_buckets_mask = 0 |
Always equal to m_buckets.size() - 1. | |
std::vector< bucket_type > | m_buckets |
std::vector< std::mutex > | m_bucket_mutexes |
float | m_max_load_factor = 1.0f |
hasher | m_hash = hasher() |
key_equal | m_equals = key_equal() |
allocator_type | m_allocator |
Static Private Attributes | |
static constexpr bool | allow_transparent = detail::is_transparent<Hash>() && detail::is_transparent<Equals>() |
True iff the hash and equals functions allow transparent lookup,. | |
Friends | |
template<typename Key_ , typename T , typename Hash_ , typename KeyEqual , typename Allocator_ , bool ThreadSafe_, bool Resize_> | |
class | unordered_map |
template<typename Key_ , typename T , typename Hash_ , typename KeyEqual , typename Allocator_ , bool ThreadSafe_, bool Resize_> | |
class | unordered_map |
A unordered_set with a subset of the interface of std::unordered_set that only stores a single pointer for each element.
Only supports input iterators (not bidirectional) compared to std::unordered_set. Furthermore, iterating over all elements in the set is O(n + m), where n is the number of elements in the set and m the number of empty buckets. Also incrementing the iterator is O(m) as opposed to O(1) as the standard mandates.
Additionally, the unordered_set supports allocators that have a specialized allocate_args(args...) to vary the allocation size based on the arguments used. This is required to store _aterm_appl classes with the function symbol arity determined at runtime.
Threadsafe enables concurrent emplace calls, and Resize enables automatically resizing if needed.
Definition at line 74 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::allocator_type = typename bucket_type::NodeAllocator |
Definition at line 218 of file unordered_set.h.
|
private |
Definition at line 81 of file unordered_set.h.
|
private |
Combine the bucket list and a lock that locks modifications to the bucket list.
Definition at line 80 of file unordered_set.h.
|
private |
Definition at line 82 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::const_iterator = unordered_set_iterator<bucket_type, true> |
Definition at line 227 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::const_local_iterator = typename bucket_type::const_iterator |
Definition at line 225 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::const_pointer = typename std::allocator_traits<Allocator>::const_pointer |
Definition at line 223 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::const_reference = const value_type& |
Definition at line 221 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::difference_type = std::ptrdiff_t |
Definition at line 231 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::hasher = Hash |
Definition at line 216 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::iterator = const_iterator |
Definition at line 228 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::key_equal = Equals |
Definition at line 217 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::key_type = Key |
Definition at line 214 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::local_iterator = typename bucket_type::const_iterator |
Definition at line 226 of file unordered_set.h.
|
private |
Definition at line 83 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::pointer = typename std::allocator_traits<Allocator>::pointer |
Definition at line 222 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::reference = value_type& |
Definition at line 220 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::size_type = std::size_t |
Definition at line 230 of file unordered_set.h.
using mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::value_type = Key |
Definition at line 215 of file unordered_set.h.
|
inline |
Definition at line 233 of file unordered_set.h.
|
inlineexplicit |
Constructs an unordered_set that contains bucket_count number of buckets.
Definition at line 236 of file unordered_set.h.
mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::unordered_set | ( | const unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize > & | set | ) |
|
default |
mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::~unordered_set | ( | ) |
|
inline |
Definition at line 260 of file unordered_set.h.
|
inline |
Definition at line 264 of file unordered_set.h.
|
inline |
Definition at line 310 of file unordered_set.h.
|
inline |
Definition at line 313 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 324 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 320 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 323 of file unordered_set.h.
|
inlinenoexcept |
Not standard.
Definition at line 341 of file unordered_set.h.
|
inline |
Definition at line 268 of file unordered_set.h.
|
inline |
Definition at line 316 of file unordered_set.h.
|
inline |
Definition at line 269 of file unordered_set.h.
|
inline |
Definition at line 317 of file unordered_set.h.
void mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::clear | ( | ) |
Removes all elements from the set.
Does not free the vector of buckets itself.
size_type mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::count | ( | const Args &... | args | ) | const |
Counts the number of occurrences of the given key (1 when it exists and 0 otherwise).
std::pair< iterator, bool > mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::emplace | ( | Args &&... | args | ) |
Inserts an element Key(args...) into the set if it did not already exist.
|
private |
Inserts T(args...) into the given bucket, assumes that it did not exists before. \threadsafe.
|
inlinenoexcept |
Definition at line 272 of file unordered_set.h.
|
inline |
Definition at line 261 of file unordered_set.h.
|
inline |
Definition at line 265 of file unordered_set.h.
|
inline |
Definition at line 311 of file unordered_set.h.
|
inline |
Definition at line 314 of file unordered_set.h.
void mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::erase | ( | const Args &... | args | ) |
Erases the given key_type(args...) from the unordered set.
iterator mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::erase | ( | const_iterator | it | ) |
Erases the element pointed to by the iterator.
|
private |
Removes T(args...) from the set.
iterator mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::find | ( | const Args &... | args | ) |
const_iterator mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::find | ( | const Args &... | args | ) | const |
Searches whether an object key_type(args...) occurs in the set.
|
private |
|
private |
Searches for the element in the given bucket.
|
inlinenoexcept |
Definition at line 256 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 257 of file unordered_set.h.
|
inline |
Definition at line 336 of file unordered_set.h.
|
inline |
Definition at line 337 of file unordered_set.h.
|
inline |
Definition at line 326 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 321 of file unordered_set.h.
|
inline |
Definition at line 327 of file unordered_set.h.
|
inline |
Definition at line 328 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 276 of file unordered_set.h.
unordered_set & mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::operator= | ( | const unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize > & | set | ) |
|
default |
void mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::rehash | ( | size_type | number_of_buckets | ) |
Resize the number buckets to at least number_of_buckets.
void mcrl2::utilities::unordered_set< Key, Hash, Equals, Allocator, ThreadSafe, Resize >::rehash_if_needed | ( | ) |
Resizes the hash table if necessary.
Not standard.
|
inline |
Resizes the set to the given number of elements.
Definition at line 334 of file unordered_set.h.
|
inlinenoexcept |
Definition at line 275 of file unordered_set.h.
|
friend |
Definition at line 86 of file unordered_set.h.
|
friend |
Definition at line 349 of file unordered_set.h.
|
staticconstexprprivate |
True iff the hash and equals functions allow transparent lookup,.
Definition at line 369 of file unordered_set.h.
|
private |
Definition at line 384 of file unordered_set.h.
|
private |
Definition at line 378 of file unordered_set.h.
|
private |
Definition at line 377 of file unordered_set.h.
|
private |
Always equal to m_buckets.size() - 1.
Definition at line 375 of file unordered_set.h.
|
private |
Definition at line 383 of file unordered_set.h.
|
private |
Definition at line 382 of file unordered_set.h.
|
private |
Definition at line 380 of file unordered_set.h.
|
private |
The number of elements stored in this set.
Definition at line 372 of file unordered_set.h.