|
|
using | key_type = typename buckets_t::key_type |
|
using | mapped_type = typename buckets_t::mapped_type |
|
using | value_type = typename buckets_t::value_type |
|
using | size_type = typename buckets_t::size_type |
|
using | difference_type = std::ptrdiff_t |
|
using | hasher = Hash |
|
using | key_equal = KeyEqual |
|
using | allocator_type = typename buckets_t::allocator_type |
|
using | reference = typename buckets_t::reference |
|
using | const_reference = typename buckets_t::const_reference |
|
using | pointer = typename buckets_t::pointer |
|
using | const_pointer = typename buckets_t::const_pointer |
|
|
|
| cuckoohash_map (size_type n=DEFAULT_SIZE, const Hash &hf=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator()) |
|
template<typename InputIt > |
| cuckoohash_map (InputIt first, InputIt last, size_type n=DEFAULT_SIZE, const Hash &hf=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator()) |
|
| cuckoohash_map (const cuckoohash_map &other)=default |
|
| cuckoohash_map (const cuckoohash_map &other, const Allocator &alloc) |
|
| cuckoohash_map (cuckoohash_map &&other)=default |
|
| cuckoohash_map (cuckoohash_map &&other, const Allocator &alloc) |
|
| cuckoohash_map (std::initializer_list< value_type > init, size_type n=DEFAULT_SIZE, const Hash &hf=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator()) |
|
void | swap (cuckoohash_map &other) noexcept |
|
cuckoohash_map & | operator= (const cuckoohash_map &other)=default |
|
cuckoohash_map & | operator= (cuckoohash_map &&other)=default |
|
cuckoohash_map & | operator= (std::initializer_list< value_type > ilist) |
|
|
Methods for getting information about the table. Methods that query changing properties of the table are not synchronized with concurrent operations, and may return out-of-date information if the table is being concurrently modified. They will also continue to work after the container has been moved.
|
hasher | hash_function () const |
|
key_equal | key_eq () const |
|
allocator_type | get_allocator () const |
|
size_type | hashpower () const |
|
size_type | bucket_count () const |
|
bool | empty () const |
|
size_type | size () const |
|
size_type | capacity () const |
|
double | load_factor () const |
|
void | minimum_load_factor (const double mlf) |
|
double | minimum_load_factor () const |
|
void | maximum_hashpower (size_type mhp) |
|
size_type | maximum_hashpower () const |
|
void | max_num_worker_threads (size_type extra_threads) |
|
size_type | max_num_worker_threads () const |
|
|
These are operations that affect the data in the table. They are safe to call concurrently with each other.
|
template<typename K , typename F > |
bool | find_fn (const K &key, F fn) const |
|
template<typename K , typename F > |
bool | update_fn (const K &key, F fn) |
|
template<typename K , typename F > |
bool | erase_fn (const K &key, F fn) |
|
template<typename K , typename F , typename... Args> |
bool | uprase_fn (K &&key, F fn, Args &&... val) |
|
template<typename K , typename F , typename... Args> |
bool | upsert (K &&key, F fn, Args &&... val) |
|
template<typename K > |
bool | find (const K &key, mapped_type &val) const |
|
template<typename K > |
mapped_type | find (const K &key) const |
|
template<typename K > |
bool | contains (const K &key) const |
|
template<typename K , typename V > |
bool | update (const K &key, V &&val) |
|
template<typename K , typename... Args> |
bool | insert (K &&key, Args &&... val) |
|
template<typename K , typename V > |
bool | insert_or_assign (K &&key, V &&val) |
|
template<typename K > |
bool | erase (const K &key) |
|
bool | rehash (size_type n) |
|
bool | reserve (size_type n) |
|
void | clear () |
|
locked_table | lock_table () |
|
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
This type is defined as an std::pair
. Note that table behavior is undefined if a user-defined specialization of std::pair<Key, T>
or std::pair<const Key, T>
exists.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename InputIt >
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::cuckoohash_map |
( |
InputIt |
first, |
|
|
InputIt |
last, |
|
|
size_type |
n = DEFAULT_SIZE , |
|
|
const Hash & |
hf = Hash() , |
|
|
const KeyEqual & |
equal = KeyEqual() , |
|
|
const Allocator & |
alloc = Allocator() |
|
) |
| |
|
inline |
Constructs the map with the contents of the range
[first, last]. If multiple elements in the range have equivalent keys, it is unspecified which element is inserted.
- Parameters
-
first | the beginning of the range to copy from |
last | the end of the range to copy from |
n | the number of elements to reserve space for initially |
hf | hash function instance to use |
equal | equality function instance to use |
alloc | allocator instance to use |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::cuckoohash_map |
( |
const cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > & |
other | ) |
|
|
default |
Copy constructor. If other
is being modified concurrently, behavior is unspecified.
- Parameters
-
other | the map being copied |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::cuckoohash_map |
( |
const cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > & |
other, |
|
|
const Allocator & |
alloc |
|
) |
| |
|
inline |
Copy constructor with separate allocator. If other
is being modified concurrently, behavior is unspecified.
- Parameters
-
other | the map being copied |
alloc | the allocator instance to use with the map |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::cuckoohash_map |
( |
cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > && |
other | ) |
|
|
default |
Move constructor. If other
is being modified concurrently, behavior is unspecified.
- Parameters
-
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::cuckoohash_map |
( |
cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > && |
other, |
|
|
const Allocator & |
alloc |
|
) |
| |
|
inline |
Move constructor with separate allocator. If the map being moved is being modified concurrently, behavior is unspecified.
- Parameters
-
other | the map being moved |
alloc | the allocator instance to use with the map |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Removes all elements in the table, calling their destructors.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K >
Returns whether or not key
is in the table. Equivalent to find_fn with a functor that does nothing.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K >
Erases the key from the table. Equivalent to calling erase_fn with a functor that just returns true.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename F >
Searches for key
in the table, and invokes fn
on the value if the key is found. The functor can mutate the value, and should return true
in order to erase the element, and false
otherwise.
- Template Parameters
-
K | type of the key |
F | type of the functor. It should implement the method bool operator()(mapped_type&) . |
- Parameters
-
key | the key to possibly erase from the table |
fn | the functor to invoke if the element is found |
- Returns
- true if
key
was found and fn
invoked, false otherwise
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K >
Searches the table for key
, and returns the associated value it finds. mapped_type
must be CopyConstructible
.
- Template Parameters
-
- Parameters
-
- Returns
- the value associated with the given key
- Exceptions
-
std::out_of_range | if the key is not found |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K >
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::find |
( |
const K & |
key, |
|
|
mapped_type & |
val |
|
) |
| const |
|
inline |
Copies the value associated with key
into val
. Equivalent to calling find_fn with a functor that copies the value into val
. mapped_type
must be CopyAssignable
.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename F >
Searches the table for key
, and invokes fn
on the value. fn
is not allowed to modify the contents of the value if found.
- Template Parameters
-
K | type of the key. This can be any type comparable with key_type |
F | type of the functor. It should implement the method void operator()(const mapped_type&) . |
- Parameters
-
key | the key to search for |
fn | the functor to invoke if the element is found |
- Returns
- true if the key was found and functor invoked, false otherwise
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Returns the hashpower of the table, which is log2(bucket_count()).
- Returns
- the hashpower
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename... Args>
Inserts the key-value pair into the table. Equivalent to calling upsert with a functor that does nothing.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename V >
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::insert_or_assign |
( |
K && |
key, |
|
|
V && |
val |
|
) |
| |
|
inline |
Inserts the key-value pair into the table. If the key is already in the table, assigns the existing mapped value to val
. Equivalent to calling upsert with a functor that assigns the mapped value to val
.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Returns the percentage the table is filled, that is, size() ÷ capacity().
- Returns
- load factor of the table
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
void libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::max_num_worker_threads |
( |
size_type |
extra_threads | ) |
|
|
inline |
Set the maximum number of extra worker threads the table can spawn when doing large batch operations. Currently batch operations occur in the following scenarios.
- Any resizing operation which invokes cuckoo_expand_simple. This includes any explicit rehash/resize operation, or any general resize if the data is not nothrow-move-constructible.
- Creating a locked_table or resizing within a locked_table.
- Parameters
-
num_threads | the number of extra threads |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Sets the maximum hashpower the table can be. If set to NO_MAXIMUM_HASHPOWER, there will be no limit on the hashpower. Otherwise, the table will not be able to expand beyond the given hashpower, either by an explicit or an automatic expansion.
- Parameters
-
mhp | the hashpower to set the maximum to |
- Exceptions
-
std::invalid_argument | if the current hashpower exceeds the limit |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
void libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::minimum_load_factor |
( |
const double |
mlf | ) |
|
|
inline |
Sets the minimum load factor allowed for automatic expansions. If an expansion is needed when the load factor of the table is lower than this threshold, load_factor_too_low is thrown. It will not be thrown for an explicitly-triggered expansion.
- Parameters
-
mlf | the load factor to set the minimum to |
- Exceptions
-
std::invalid_argument | if the given load factor is less than 0.0 or greater than 1.0 |
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
cuckoohash_map& libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::operator= |
( |
const cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > & |
other | ) |
|
|
default |
Copy assignment operator. If other
is being modified concurrently, behavior is unspecified.
- Parameters
-
other | the map to assign from |
- Returns
*this
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
cuckoohash_map& libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::operator= |
( |
cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > && |
other | ) |
|
|
default |
Move assignment operator. If other
is being modified concurrently, behavior is unspecified.
- Parameters
-
other | the map to assign from |
- Returns
*this
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Resizes the table to the given hashpower. If this hashpower is not larger than the current hashpower, then it decreases the hashpower to the maximum of the specified value and the smallest hashpower that can hold all the elements currently in the table.
- Parameters
-
n | the hashpower to set for the table |
- Returns
- true if the table changed size, false otherwise
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
Reserve enough space in the table for the given number of elements. If the table can already hold that many elements, the function will shrink the table to the smallest hashpower that can hold the maximum of the specified amount and the current table size.
- Parameters
-
n | the number of elements to reserve space for |
- Returns
- true if the size of the table changed, false otherwise
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename V >
Updates the value associated with key
to val
. Equivalent to calling update_fn with a functor that assigns the existing mapped value to val
. mapped_type
must be MoveAssignable
or CopyAssignable
.
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename F >
Searches the table for key
, and invokes fn
on the value. fn
is allow to modify the contents of the value if found.
- Template Parameters
-
K | type of the key. This can be any type comparable with key_type |
F | type of the functor. It should implement the method void operator()(mapped_type&) . |
- Parameters
-
key | the key to search for |
fn | the functor to invoke if the element is found |
- Returns
- true if the key was found and functor invoked, false otherwise
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename F , typename... Args>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::uprase_fn |
( |
K && |
key, |
|
|
F |
fn, |
|
|
Args &&... |
val |
|
) |
| |
|
inline |
Searches for key
in the table. If the key is not found and must be inserted, the pair will be constructed by forwarding the given key and values. If there is no room left in the table, it will be automatically expanded. Expansion may throw exceptions.
Upon finding or inserting the key, fn
is invoked on the value, with an additional UpsertContext enum indicating whether the key was newly-inserted or already existed in the table. The functor can mutate the value, and should return true
in order to erase the element, and false
otherwise.
Note: if fn
is only invocable with a single mapped_type&
argument, it will only be invoked if the key was already in the table.
- Template Parameters
-
K | type of the key |
F | type of the functor. It must implement either bool operator()(mapped_type&, UpsertContext) or bool operator()(mapped_type&) . |
Args | list of types for the value constructor arguments |
- Parameters
-
key | the key to insert into the table |
fn | the functor to invoke if the element is found. If your fn needs more data that just the value being modified, consider implementing it as a lambda with captured arguments. |
val | a list of constructor arguments with which to create the value |
- Returns
- true if a new key was inserted, false if the key was already in the table
template<class Key , class T , class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<const Key, T>>, std::size_t SLOT_PER_BUCKET = DEFAULT_SLOT_PER_BUCKET>
template<typename K , typename F , typename... Args>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::upsert |
( |
K && |
key, |
|
|
F |
fn, |
|
|
Args &&... |
val |
|
) |
| |
|
inline |
Equivalent to calling uprase_fn with a functor that modifies the given value and always returns false (meaning the element is not removed). The passed-in functor must implement either bool operator()(mapped_type&, UpsertContext)
or bool operator()(mapped_type&)
.