cds  2.3.2
cds::container::CuckooMap< Key, T, Traits > Class Template Reference

Cuckoo hash map. More...

#include <cds/container/cuckoo_map.h>

Inheritance diagram for cds::container::CuckooMap< Key, T, Traits >:
cds::intrusive::CuckooSet< std::pair< Key const, T >, Traits >

Public Types

typedef Key key_type
 key type
 
typedef T mapped_type
 value type stored in the container
 
typedef std::pair< key_type const, mapped_typevalue_type
 Key-value pair type stored in the map.
 
typedef Traits traits
 Map traits.
 
typedef traits::hash hash
 hash functor tuple wrapped for internal use
 
typedef base_class::hash_tuple_type hash_tuple_type
 hash tuple type
 
typedef base_class::mutex_policy mutex_policy
 Concurrent access policy, see cuckoo::traits::mutex_policy.
 
typedef base_class::stat stat
 internal statistics type
 
typedef base_class::key_equal_to key_equal_to
 Key equality functor; used only for unordered probe-set.
 
typedef base_class::key_comparator key_comparator
 key comparing functor based on opt::compare and opt::less option setter. Used only for ordered probe set
 
typedef base_class::allocator allocator
 allocator type used for internal bucket table allocations
 
typedef std::conditional< std::is_same< typename traits::node_allocator, opt::none >::value, allocator, typename traits::node_allocator >::type node_allocator
 Node allocator type.
 
typedef traits::item_counter item_counter
 item counter type
 

Public Member Functions

 CuckooMap ()
 Default constructor. More...
 
 CuckooMap (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold=0)
 Constructs an object with given probe set size and threshold. More...
 
 CuckooMap (hash_tuple_type const &h)
 Constructs an object with given hash functor tuple. More...
 
 CuckooMap (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold, hash_tuple_type const &h)
 Constructs a map with given probe set properties and hash functor tuple. More...
 
 CuckooMap (hash_tuple_type &&h)
 Constructs a map with given hash functor tuple (move semantics) More...
 
 CuckooMap (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold, hash_tuple_type &&h)
 Constructs a map with given probe set properties and hash functor tuple (move semantics) More...
 
 ~CuckooMap ()
 Destructor clears the map.
 
template<typename K >
bool insert (K const &key)
 Inserts new node with key and default value. More...
 
template<typename K , typename V >
bool insert (K const &key, V const &val)
 Inserts new node. More...
 
template<typename K , typename Func >
bool insert_with (const K &key, Func func)
 Inserts new node and initialize it by a functor. More...
 
template<typename K , typename... Args>
bool emplace (K &&key, Args &&... args)
 For key key inserts data of type value_type constructed with std::forward<Args>(args)... More...
 
template<typename K , typename Func >
std::pair< bool, bool > update (K const &key, Func func, bool bAllowInsert=true)
 Updates the node. More...
 
template<typename K >
bool erase (K const &key)
 Delete key from the map. More...
 
template<typename K , typename Predicate >
bool erase_with (K const &key, Predicate pred)
 Deletes the item from the list using pred predicate for searching. More...
 
template<typename K , typename Func >
bool erase (K const &key, Func f)
 Delete key from the map. More...
 
template<typename K , typename Predicate , typename Func >
bool erase_with (K const &key, Predicate pred, Func f)
 Deletes the item from the list using pred predicate for searching. More...
 
template<typename K , typename Func >
bool find (K const &key, Func f)
 Find the key key. More...
 
template<typename K , typename Predicate , typename Func >
bool find_with (K const &key, Predicate pred, Func f)
 Find the key val using pred predicate for comparing. More...
 
template<typename K >
bool contains (K const &key)
 Checks whether the map contains key. More...
 
template<typename K , typename Predicate >
bool contains (K const &key, Predicate pred)
 Checks whether the map contains key using pred predicate for searching. More...
 
void clear ()
 Clears the map.
 
bool empty () const
 Checks if the map is empty. More...
 
size_t size () const
 Returns item count in the map.
 
size_t bucket_count () const
 Returns the size of hash table. More...
 
size_t lock_count () const
 Returns lock array size. More...
 
stat const & statistics () const
 Returns const reference to internal statistics.
 
mutex_policy::statistics_type const & mutex_policy_statistics () const
 Returns const reference to mutex policy internal statistics.
 

Static Public Attributes

static bool const c_isSorted = base_class::c_isSorted
 whether the probe set should be ordered
 
static size_t const c_nArity = base_class::c_nArity
 the arity of cuckoo hashing: the number of hash functors provided; minimum 2.
 
static unsigned int const c_nDefaultProbesetSize = base_class::c_nDefaultProbesetSize
 default probeset size
 
static size_t const c_nDefaultInitialSize = base_class::c_nDefaultInitialSize
 default initial size
 
static unsigned int const c_nRelocateLimit = base_class::c_nRelocateLimit
 Count of attempts to relocate before giving up.
 

Additional Inherited Members

- Protected Types inherited from cds::intrusive::CuckooSet< std::pair< Key const, T >, Traits >
typedef std::pair< Key const, T > value_type
 The value type stored in the set.
 
typedef Traits traits
 Set traits.
 
typedef traits::hook hook
 hook type
 
typedef hook::node_type node_type
 node type
 
typedef get_node_traits< value_type, node_type, hook >::type node_traits
 node traits
 
typedef traits::hash hash
 hash functor tuple wrapped for internal use
 
typedef hash::hash_tuple_type hash_tuple_type
 Type of hash tuple.
 
typedef traits::stat stat
 internal statistics type
 
typedef traits::mutex_policy original_mutex_policy
 Concurrent access policy, see cuckoo::traits::mutex_policy.
 
typedef opt::details::make_equal_to< value_type, traits, !c_isSorted >::type key_equal_to
 Key equality functor; used only for unordered probe-set.
 
typedef opt::details::make_comparator< value_type, traits >::type key_comparator
 key comparing functor based on opt::compare and opt::less option setter. Used only for ordered probe set
 
typedef traits::allocator allocator
 allocator type
 
typedef traits::item_counter item_counter
 item counter type
 
typedef traits::disposer disposer
 node disposer
 
- Protected Member Functions inherited from cds::intrusive::CuckooSet< std::pair< Key const, T >, Traits >
 CuckooSet ()
 Default constructor. More...
 
 CuckooSet (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold=0)
 Constructs the set object with given probe set size and threshold. More...
 
 CuckooSet (hash_tuple_type const &h)
 Constructs the set object with given hash functor tuple. More...
 
 CuckooSet (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold, hash_tuple_type const &h)
 Constructs the set object with given probe set properties and hash functor tuple. More...
 
 CuckooSet (hash_tuple_type &&h)
 Constructs the set object with given hash functor tuple (move semantics) More...
 
 CuckooSet (size_t nInitialSize, unsigned int nProbesetSize, unsigned int nProbesetThreshold, hash_tuple_type &&h)
 Constructs the set object with given probe set properties and hash functor tuple (move semantics) More...
 
 ~CuckooSet ()
 Destructor.
 
bool insert (value_type &val)
 Inserts new node. More...
 
bool insert (value_type &val, Func f)
 Inserts new node. More...
 
std::pair< bool, bool > update (value_type &val, Func func, bool bAllowInsert=true)
 Updates the node. More...
 
bool unlink (value_type &val)
 Unlink the item val from the set. More...
 
value_typeerase (Q const &val)
 Deletes the item from the set. More...
 
value_typeerase (Q const &val, Func f)
 Delete the item from the set. More...
 
value_typeerase_with (Q const &val, Predicate pred)
 Deletes the item from the set using pred predicate for searching. More...
 
value_typeerase_with (Q const &val, Predicate pred, Func f)
 Deletes the item from the set using pred predicate for searching. More...
 
bool find (Q &val, Func f)
 Find the key val. More...
 
bool find_with (Q &val, Predicate pred, Func f)
 Find the key val using pred predicate for comparing. More...
 
bool contains (Q const &key)
 Checks whether the set contains key. More...
 
bool contains (Q const &key, Predicate pred)
 Checks whether the set contains key using pred predicate for searching. More...
 
void clear ()
 Clears the set. More...
 
void clear_and_dispose (Disposer oDisposer)
 Clears the set and calls disposer for each item. More...
 
bool empty () const
 Checks if the set is empty. More...
 
size_t size () const
 Returns item count in the set.
 
size_t bucket_count () const
 Returns the size of hash table. More...
 
size_t lock_count () const
 Returns lock array size.
 
stat const & statistics () const
 Returns const reference to internal statistics.
 
mutex_policy::statistics_type const & mutex_policy_statistics () const
 Returns const reference to mutex policy internal statistics.
 
- Protected Attributes inherited from cds::intrusive::CuckooSet< std::pair< Key const, T >, Traits >
bucket_entry * m_BucketTable [c_nArity]
 Bucket tables.
 
atomics::atomic< size_t > m_nBucketMask
 Hash bitmask; bucket table size minus 1.
 
unsigned int const m_nProbesetSize
 Probe set size.
 
unsigned int const m_nProbesetThreshold
 Probe set threshold.
 
hash m_Hash
 Hash functor tuple.
 
mutex_policy m_MutexPolicy
 concurrent access policy
 
item_counter m_ItemCounter
 item counter
 
stat m_Stat
 internal statistics
 
- Static Protected Attributes inherited from cds::intrusive::CuckooSet< std::pair< Key const, T >, Traits >
static bool const c_isSorted
 Probe set should be ordered or not. More...
 
static size_t const c_nArity
 the arity of cuckoo hashing: the number of hash functors provided; minimum 2.
 
static unsigned int const c_nDefaultProbesetSize
 default probeset size
 
static size_t const c_nDefaultInitialSize
 default initial size
 
static unsigned int const c_nRelocateLimit
 Count of attempts to relocate before giving up.
 

Detailed Description

template<typename Key, typename T, typename Traits = cuckoo::traits>
class cds::container::CuckooMap< Key, T, Traits >

Cuckoo hash map.

Source

  • [2007] M.Herlihy, N.Shavit, M.Tzafrir "Concurrent Cuckoo Hashing. Technical report"
  • [2008] Maurice Herlihy, Nir Shavit "The Art of Multiprocessor Programming"

About Cuckoo hashing

[From "The Art of Multiprocessor Programming"] Cuckoo hashing is a hashing algorithm in which a newly added item displaces any earlier item occupying the same slot. For brevity, a table is a k-entry array of items. For a hash set f size N = 2k we use a two-entry array of tables, and two independent hash functions, h0, h1: KeyRange -> 0,...,k-1 mapping the set of possible keys to entries in he array. To test whether a value x is in the set, find(x) tests whether either table[0][h0(x)] or table[1][h1(x)] is equal to x. Similarly, erase(x)checks whether x is in either table[0][h0(x)] or table[1][h1(x)], ad removes it if found.

The insert(x) successively "kicks out" conflicting items until every key has a slot. To add x, the method swaps x with y, the current occupant of table[0][h0(x)]. If the prior value was nullptr, it is done. Otherwise, it swaps the newly nest-less value y for the current occupant of table[1][h1(y)] in the same way. As before, if the prior value was nullptr, it is done. Otherwise, the method continues swapping entries (alternating tables) until it finds an empty slot. We might not find an empty slot, either because the table is full, or because the sequence of displacement forms a cycle. We therefore need an upper limit on the number of successive displacements we are willing to undertake. When this limit is exceeded, we resize the hash table, choose new hash functions and start over.

For concurrent cuckoo hashing, rather than organizing the set as a two-dimensional table of items, we use two-dimensional table of probe sets, where a probe set is a constant-sized set of items with the same hash code. Each probe set holds at most PROBE_SIZE items, but the algorithm tries to ensure that when the set is quiescent (i.e no method call in progress) each probe set holds no more than THRESHOLD < PROBE_SET items. While method calls are in-flight, a probe set may temporarily hold more than THRESHOLD but never more than PROBE_SET items.

In current implementation, a probe set can be defined either as a (single-linked) list or as a fixed-sized vector, optionally ordered.

In description above two-table cuckoo hashing (k = 2) has been considered. We can generalize this approach for k >= 2 when we have k hash functions h[0], ... h[k-1] and k tables table[0], ... table[k-1].

The search in probe set is linear, the complexity is O(PROBE_SET) . The probe set may be ordered or not. Ordered probe set can be a little better since the average search complexity is O(PROBE_SET/2). However, the overhead of sorting can eliminate a gain of ordered search.

The probe set is ordered if compare or less is specified in Traits template parameter. Otherwise, the probe set is unordered and Traits must contain equal_to predicate.

Template arguments:

  • Key - key type
  • T - the type stored in the map.
  • Traits - map traits, default is cuckoo::traits. It is possible to declare option-based set with cuckoo::make_traits metafunction result as Traits template argument.

Examples

Declares cuckoo mapping from std::string to struct foo. For cuckoo hashing we should provide at least two hash functions:

struct hash1 {
size_t operator()(std::string const& s) const
{
return cds::opt::v::hash<std::string>( s );
}
};
struct hash2: private hash1 {
size_t operator()(std::string const& s) const
{
size_t h = ~( hash1::operator()(s));
return ~h + 0x9e3779b9 + (h << 6) + (h >> 2);
}
};

Cuckoo-map with list-based unordered probe set and storing hash values

#include <cds/container/cuckoo_map.h>
// Declare type traits
struct my_traits: public cds::container::cuckoo::traits
{
typedef std::equal_to< std::string > equal_to;
typedef std::tuple< hash1, hash2 > hash;
static bool const store_hash = true;
};
// Declare CuckooMap type
// Equal option-based declaration
typedef cds::container::CuckooMap< std::string, foo,
>::type
> opt_cuckoo_map;

If we provide less functor instead of equal_to we get as a result a cuckoo map with ordered probe set that may improve performance. Example for ordered vector-based probe-set:

#include <cds/container/cuckoo_map.h>
// Declare type traits
// We use a vector of capacity 4 as probe-set container and store hash values in the node
struct my_traits: public cds::container::cuckoo::traits
{
typedef std::less< std::string > less;
typedef std::tuple< hash1, hash2 > hash;
typedef cds::container::cuckoo::vector<4> probeset_type;
static bool const store_hash = true;
};
// Declare CuckooMap type
// Equal option-based declaration
typedef cds::container::CuckooMap< std::string, foo,
cds::opt::hash< std::tuple< hash1, hash2 > >
>::type
> opt_cuckoo_map;

Constructor & Destructor Documentation

◆ CuckooMap() [1/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( )
inline

Default constructor.

Initial size = c_nDefaultInitialSize

Probe set size:

  • c_nDefaultProbesetSize if probeset_type is cuckoo::list
  • Capacity if probeset_type is cuckoo::vector<Capacity>

Probe set threshold = probe set size - 1

◆ CuckooMap() [2/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( size_t  nInitialSize,
unsigned int  nProbesetSize,
unsigned int  nProbesetThreshold = 0 
)
inline

Constructs an object with given probe set size and threshold.

If probe set type is cuckoo::vector<Capacity> vector then nProbesetSize should be equal to vector's Capacity.

Parameters
nInitialSizeInitial map size; if 0 - use default initial size c_nDefaultInitialSize
nProbesetSizeprobe set size
nProbesetThresholdprobe set threshold, nProbesetThreshold < nProbesetSize. If 0, nProbesetThreshold = nProbesetSize - 1

◆ CuckooMap() [3/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( hash_tuple_type const &  h)
inline

Constructs an object with given hash functor tuple.

The probe set size and threshold are set as default, see CuckooSet()

Parameters
hhash functor tuple of type std::tuple<H1, H2, ... Hn> where n == c_nArity

◆ CuckooMap() [4/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( size_t  nInitialSize,
unsigned int  nProbesetSize,
unsigned int  nProbesetThreshold,
hash_tuple_type const &  h 
)
inline

Constructs a map with given probe set properties and hash functor tuple.

If probe set type is cuckoo::vector<Capacity> vector then nProbesetSize should be equal to vector's Capacity.

Parameters
nInitialSizeInitial map size; if 0 - use default initial size c_nDefaultInitialSize
nProbesetSizeprobe set size
nProbesetThresholdprobe set threshold, nProbesetThreshold < nProbesetSize. If 0, nProbesetThreshold = nProbesetSize - 1
hhash functor tuple of type std::tuple<H1, H2, ... Hn> where n == c_nArity

◆ CuckooMap() [5/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( hash_tuple_type &&  h)
inline

Constructs a map with given hash functor tuple (move semantics)

The probe set size and threshold are set as default, see CuckooSet()

Parameters
hhash functor tuple of type std::tuple<H1, H2, ... Hn> where n == c_nArity

◆ CuckooMap() [6/6]

template<typename Key , typename T , typename Traits = cuckoo::traits>
cds::container::CuckooMap< Key, T, Traits >::CuckooMap ( size_t  nInitialSize,
unsigned int  nProbesetSize,
unsigned int  nProbesetThreshold,
hash_tuple_type &&  h 
)
inline

Constructs a map with given probe set properties and hash functor tuple (move semantics)

If probe set type is cuckoo::vector<Capacity> vector then nProbesetSize should be equal to vector's Capacity.

Parameters
nInitialSizeInitial map size; if 0 - use default initial size c_nDefaultInitialSize
nProbesetSizeprobe set size
nProbesetThresholdprobe set threshold, nProbesetThreshold < nProbesetSize. If 0, nProbesetThreshold = nProbesetSize - 1
hhash functor tuple of type std::tuple<H1, H2, ... Hn> where n == c_nArity

Member Function Documentation

◆ bucket_count()

template<typename Key , typename T , typename Traits = cuckoo::traits>
size_t cds::container::CuckooMap< Key, T, Traits >::bucket_count ( ) const
inline

Returns the size of hash table.

The hash table size is non-constant and can be increased via resizing.

◆ contains() [1/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K >
bool cds::container::CuckooMap< Key, T, Traits >::contains ( K const &  key)
inline

Checks whether the map contains key.

The function searches the item with key equal to key and returns true if it is found, and false otherwise.

◆ contains() [2/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Predicate >
bool cds::container::CuckooMap< Key, T, Traits >::contains ( K const &  key,
Predicate  pred 
)
inline

Checks whether the map contains key using pred predicate for searching.

The function is similar to contains( key ) but pred is used for key comparing. Less functor has the interface like std::less. Less must imply the same element order as the comparator used for building the map.

◆ emplace()

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename... Args>
bool cds::container::CuckooMap< Key, T, Traits >::emplace ( K &&  key,
Args &&...  args 
)
inline

For key key inserts data of type value_type constructed with std::forward<Args>(args)...

Returns true if inserting successful, false otherwise.

◆ empty()

template<typename Key , typename T , typename Traits = cuckoo::traits>
bool cds::container::CuckooMap< Key, T, Traits >::empty ( ) const
inline

Checks if the map is empty.

Emptiness is checked by item counting: if item count is zero then the map is empty.

◆ erase() [1/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K >
bool cds::container::CuckooMap< Key, T, Traits >::erase ( K const &  key)
inline

Delete key from the map.

Return true if key is found and deleted, false otherwise

◆ erase() [2/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Func >
bool cds::container::CuckooMap< Key, T, Traits >::erase ( K const &  key,
Func  f 
)
inline

Delete key from the map.

The function searches an item with key key, calls f functor and deletes the item. If key is not found, the functor is not called.

The functor Func interface:

struct extractor {
void operator()(value_type& item) { ... }
};

Return true if key is found and deleted, false otherwise

See also: erase

◆ erase_with() [1/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Predicate >
bool cds::container::CuckooMap< Key, T, Traits >::erase_with ( K const &  key,
Predicate  pred 
)
inline

Deletes the item from the list using pred predicate for searching.

The function is an analog of erase(Q const&) but pred is used for key comparing. If cuckoo map is ordered, then Predicate should have the interface and semantics like std::less. If cuckoo map is unordered, then Predicate should have the interface and semantics like std::equal_to. Predicate must imply the same element order as the comparator used for building the map.

◆ erase_with() [2/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Predicate , typename Func >
bool cds::container::CuckooMap< Key, T, Traits >::erase_with ( K const &  key,
Predicate  pred,
Func  f 
)
inline

Deletes the item from the list using pred predicate for searching.

The function is an analog of erase(Q const&, Func) but pred is used for key comparing. If cuckoo map is ordered, then Predicate should have the interface and semantics like std::less. If cuckoo map is unordered, then Predicate should have the interface and semantics like std::equal_to. Predicate must imply the same element order as the comparator used for building the map.

◆ find()

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Func >
bool cds::container::CuckooMap< Key, T, Traits >::find ( K const &  key,
Func  f 
)
inline

Find the key key.

The function searches the item with key equal to key and calls the functor f for item found. The interface of Func functor is:

struct functor {
void operator()( value_type& item );
};

where item is the item found.

The functor may change item.second.

The function returns true if key is found, false otherwise.

◆ find_with()

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Predicate , typename Func >
bool cds::container::CuckooMap< Key, T, Traits >::find_with ( K const &  key,
Predicate  pred,
Func  f 
)
inline

Find the key val using pred predicate for comparing.

The function is an analog of find(K const&, Func) but pred is used for key comparison. If you use ordered cuckoo map, then Predicate should have the interface and semantics like std::less. If you use unordered cuckoo map, then Predicate should have the interface and semantics like std::equal_to. pred must imply the same element order as the comparator used for building the map.

◆ insert() [1/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K >
bool cds::container::CuckooMap< Key, T, Traits >::insert ( K const &  key)
inline

Inserts new node with key and default value.

The function creates a node with key and default value, and then inserts the node created into the map.

Preconditions:

  • The key_type should be constructible from a value of type K. In trivial case, K is equal to key_type.
  • The mapped_type should be default-constructible.

Returns true if inserting successful, false otherwise.

◆ insert() [2/2]

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename V >
bool cds::container::CuckooMap< Key, T, Traits >::insert ( K const &  key,
V const &  val 
)
inline

Inserts new node.

The function creates a node with copy of val value and then inserts the node created into the map.

Preconditions:

  • The key_type should be constructible from key of type K.
  • The value_type should be constructible from val of type V.

Returns true if val is inserted into the set, false otherwise.

◆ insert_with()

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Func >
bool cds::container::CuckooMap< Key, T, Traits >::insert_with ( const K &  key,
Func  func 
)
inline

Inserts new node and initialize it by a functor.

This function inserts new node with key key and if inserting is successful then it calls func functor with signature

struct functor {
void operator()( value_type& item );
};

The argument item of user-defined functor func is the reference to the map's item inserted:

  • item.first is a const reference to item's key that cannot be changed.
  • item.second is a reference to item's value that may be changed.

The key_type should be constructible from value of type K.

The function allows to split creating of new item into two part:

  • create item from key;
  • insert new item into the map;
  • if inserting is successful, initialize the value of item by calling func functor

This can be useful if complete initialization of object of value_type is heavyweight and it is preferable that the initialization should be completed only if inserting is successful.

◆ lock_count()

template<typename Key , typename T , typename Traits = cuckoo::traits>
size_t cds::container::CuckooMap< Key, T, Traits >::lock_count ( ) const
inline

Returns lock array size.

The lock array size is constant.

◆ update()

template<typename Key , typename T , typename Traits = cuckoo::traits>
template<typename K , typename Func >
std::pair<bool, bool> cds::container::CuckooMap< Key, T, Traits >::update ( K const &  key,
Func  func,
bool  bAllowInsert = true 
)
inline

Updates the node.

The operation performs inserting or changing data with lock-free manner.

If key is not found in the map, then key is inserted iff bAllowInsert is true. Otherwise, the functor func is called with item found. The functor func signature is:

struct my_functor {
void operator()( bool bNew, value_type& item );
};

with arguments:

  • bNew - true if the item has been inserted, false otherwise
  • item - an item of the map for key

Returns std::pair<bool, bool> where first is true if operation is successful, i.e. the node has been inserted or updated, second is true if new item has been added or false if the item with key already exists.


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:17 by Doxygen 1.8.13