libcuckoo  0.3.1
Classes | Friends | List of all members
libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > Class Template Reference

#include <cuckoohash_map.hh>

Classes

class  locked_table
 

Public Types

Type Declarations
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
 

Public Member Functions

Constructors, Destructors, and Assignment
 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_mapoperator= (const cuckoohash_map &other)=default
 
cuckoohash_mapoperator= (cuckoohash_map &&other)=default
 
cuckoohash_mapoperator= (std::initializer_list< value_type > ilist)
 
Table Details

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
 
Table Operations

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 ()
 

Static Public Member Functions

Table Parameters
static constexpr uint16_t slot_per_bucket ()
 

Friends

class UnitTestInternalAccess
 

Detailed Description

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>
class libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >

A concurrent hash table

Template Parameters
Keytype of keys in the table
Ttype of values in the table
Hashtype of hash functor
KeyEqualtype of equality comparison functor
Allocatortype of allocator. We suggest using an aligned allocator, because the table relies on types that are over-aligned to optimize concurrent cache usage.
SLOT_PER_BUCKETnumber of slots for each bucket in the table

Member Typedef Documentation

◆ value_type

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>
using libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::value_type = typename buckets_t::value_type

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.

Constructor & Destructor Documentation

◆ cuckoohash_map() [1/7]

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 ( size_type  n = DEFAULT_SIZE,
const Hash &  hf = Hash(),
const KeyEqual &  equal = KeyEqual(),
const Allocator &  alloc = Allocator() 
)
inline

Creates a new cuckohash_map instance

Parameters
nthe number of elements to reserve space for initially
hfhash function instance to use
equalequality function instance to use
allocallocator instance to use

◆ cuckoohash_map() [2/7]

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
firstthe beginning of the range to copy from
lastthe end of the range to copy from
nthe number of elements to reserve space for initially
hfhash function instance to use
equalequality function instance to use
allocallocator instance to use

◆ cuckoohash_map() [3/7]

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
otherthe map being copied

◆ cuckoohash_map() [4/7]

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
otherthe map being copied
allocthe allocator instance to use with the map

◆ cuckoohash_map() [5/7]

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
otherthe map being moved

◆ cuckoohash_map() [6/7]

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
otherthe map being moved
allocthe allocator instance to use with the map

◆ cuckoohash_map() [7/7]

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 ( std::initializer_list< value_type init,
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 initializer list init.

Parameters
initinitializer list to initialize the elements of the map with
nthe number of elements to reserve space for initially
hfhash function instance to use
equalequality function instance to use
allocallocator instance to use

Member Function Documentation

◆ bucket_count()

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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::bucket_count ( ) const
inline

Returns the number of buckets in the table.

Returns
the bucket count

◆ capacity()

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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::capacity ( ) const
inline

Returns the current capacity of the table, that is, bucket_count() × slot_per_bucket().

Returns
capacity of table

◆ clear()

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 >::clear ( )
inline

Removes all elements in the table, calling their destructors.

◆ contains()

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 >::contains ( const K &  key) const
inline

Returns whether or not key is in the table. Equivalent to find_fn with a functor that does nothing.

◆ empty()

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>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::empty ( ) const
inline

Returns whether the table is empty or not.

Returns
true if the table is empty, false otherwise

◆ erase()

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 >::erase ( const K &  key)
inline

Erases the key from the table. Equivalent to calling erase_fn with a functor that just returns true.

◆ erase_fn()

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 >
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::erase_fn ( const K &  key,
fn 
)
inline

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
Ktype of the key
Ftype of the functor. It should implement the method bool operator()(mapped_type&).
Parameters
keythe key to possibly erase from the table
fnthe functor to invoke if the element is found
Returns
true if key was found and fn invoked, false otherwise

◆ find() [1/2]

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 >
mapped_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::find ( const K &  key) const
inline

Searches the table for key, and returns the associated value it finds. mapped_type must be CopyConstructible.

Template Parameters
Ktype of the key
Parameters
keythe key to search for
Returns
the value associated with the given key
Exceptions
std::out_of_rangeif the key is not found

◆ find() [2/2]

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.

◆ find_fn()

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 >
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::find_fn ( const K &  key,
fn 
) const
inline

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
Ktype of the key. This can be any type comparable with key_type
Ftype of the functor. It should implement the method void operator()(const mapped_type&).
Parameters
keythe key to search for
fnthe functor to invoke if the element is found
Returns
true if the key was found and functor invoked, false otherwise

◆ get_allocator()

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>
allocator_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::get_allocator ( ) const
inline

Returns the allocator associated with the map

Returns
the associated allocator

◆ hash_function()

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>
hasher libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::hash_function ( ) const
inline

Returns the function that hashes the keys

Returns
the hash function

◆ 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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::hashpower ( ) const
inline

Returns the hashpower of the table, which is log2(bucket_count()).

Returns
the hashpower

◆ insert()

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>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::insert ( K &&  key,
Args &&...  val 
)
inline

Inserts the key-value pair into the table. Equivalent to calling upsert with a functor that does nothing.

◆ insert_or_assign()

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.

◆ key_eq()

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>
key_equal libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::key_eq ( ) const
inline

Returns the function that compares keys for equality

Returns
the key comparison function

◆ load_factor()

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>
double libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::load_factor ( ) const
inline

Returns the percentage the table is filled, that is, size() ÷ capacity().

Returns
load factor of the 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>
locked_table libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::lock_table ( )
inline

Construct a locked_table object that owns all the locks in the table.

Returns
a locked_table instance

◆ max_num_worker_threads() [1/2]

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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::max_num_worker_threads ( ) const
inline

Returns the maximum number of extra worker threads.

◆ max_num_worker_threads() [2/2]

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_threadsthe number of extra threads

◆ maximum_hashpower() [1/2]

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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::maximum_hashpower ( ) const
inline

Returns the maximum hashpower of the table

Returns
the maximum hashpower

◆ maximum_hashpower() [2/2]

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 >::maximum_hashpower ( size_type  mhp)
inline

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
mhpthe hashpower to set the maximum to
Exceptions
std::invalid_argumentif the current hashpower exceeds the limit

◆ minimum_load_factor() [1/2]

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>
double libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::minimum_load_factor ( ) const
inline

Returns the minimum load factor of the table

Returns
the minimum load factor

◆ minimum_load_factor() [2/2]

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
mlfthe load factor to set the minimum to
Exceptions
std::invalid_argumentif the given load factor is less than 0.0 or greater than 1.0

◆ operator=() [1/3]

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
otherthe map to assign from
Returns
*this

◆ operator=() [2/3]

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
otherthe map to assign from
Returns
*this

◆ operator=() [3/3]

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= ( std::initializer_list< value_type ilist)
inline

Initializer list assignment operator

Parameters
ilistan initializer list to assign from
Returns
*this

◆ rehash()

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>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::rehash ( size_type  n)
inline

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
nthe hashpower to set for the table
Returns
true if the table changed size, false otherwise

◆ reserve()

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>
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::reserve ( size_type  n)
inline

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
nthe number of elements to reserve space for
Returns
true if the size of the table changed, false otherwise

◆ size()

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>
size_type libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::size ( ) const
inline

Returns the number of elements in the table.

Returns
number of elements in the table

◆ 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>
static constexpr uint16_t libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::slot_per_bucket ( )
inlinestaticconstexpr

The number of slots per hash bucket

◆ swap()

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 >::swap ( cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET > &  other)
inlinenoexcept

Exchanges the contents of the map with those of other

Parameters
otherthe map to exchange contents with

◆ update()

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 >::update ( const K &  key,
V &&  val 
)
inline

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.

◆ update_fn()

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 >
bool libcuckoo::cuckoohash_map< Key, T, Hash, KeyEqual, Allocator, SLOT_PER_BUCKET >::update_fn ( const K &  key,
fn 
)
inline

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
Ktype of the key. This can be any type comparable with key_type
Ftype of the functor. It should implement the method void operator()(mapped_type&).
Parameters
keythe key to search for
fnthe functor to invoke if the element is found
Returns
true if the key was found and functor invoked, false otherwise

◆ uprase_fn()

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,
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
Ktype of the key
Ftype of the functor. It must implement either bool operator()(mapped_type&, UpsertContext) or bool operator()(mapped_type&).
Argslist of types for the value constructor arguments
Parameters
keythe key to insert into the table
fnthe 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.
vala 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

◆ upsert()

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,
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&).


The documentation for this class was generated from the following file: