cds  2.3.2
cds::container::StripedMap< Container, Options > Class Template Reference

Striped hash map. More...

#include <cds/container/striped_map.h>

Inheritance diagram for cds::container::StripedMap< Container, Options >:
cds::container::StripedSet< Container, Options... > cds::intrusive::StripedSet< Container, Options... >

Public Types

typedef Container underlying_container_type
 original intrusive container type for the bucket
 
typedef base_class::bucket_type bucket_type
 container type adapted for hash set
 
typedef bucket_type::value_type value_type
 pair type ( std::pair<key_type const, mapped_type> )
 
typedef value_type::first_type key_type
 key type
 
typedef value_type::second_type mapped_type
 mapped type
 
typedef base_class::hash hash
 Hash functor.
 
typedef base_class::item_counter item_counter
 Item counter.
 
typedef base_class::resizing_policy resizing_policy
 Resizing policy.
 
typedef base_class::allocator_type allocator_type
 allocator type specified in options.
 
typedef base_class::mutex_policy mutex_policy
 Mutex policy.
 

Public Member Functions

 StripedMap ()
 Default ctor. The initial capacity is 16.
 
 StripedMap (size_t nCapacity)
 Ctor with initial capacity specified. More...
 
 StripedMap (size_t nCapacity, resizing_policy const &resizingPolicy)
 Ctor with resizing policy (copy semantics) More...
 
 StripedMap (size_t nCapacity, resizing_policy &&resizingPolicy)
 Ctor with resizing policy (move semantics) More...
 
 ~StripedMap ()
 Destructor destroys internal data.
 
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 mapped_type created in-place from 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 Less , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type>
bool erase_with (K const &key, Less pred)
 Deletes the item from the map 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 Less , typename Func , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type>
bool erase_with (K const &key, Less pred, Func f)
 Deletes the item from the map 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 Less , typename Func , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type>
bool find_with (K const &key, Less pred, Func f)
 Find the key val using pred predicate. More...
 
template<typename K >
bool contains (K const &key)
 Checks whether the map contains key. More...
 
template<typename K , typename Less , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type>
bool contains (K const &key, Less pred)
 Checks whether the set 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...
 
resizing_policyget_resizing_policy ()
 Returns resizing policy object.
 
resizing_policy const & get_resizing_policy () const
 Returns resizing policy (const version)
 

Additional Inherited Members

- Protected Types inherited from cds::container::StripedSet< Container, Options... >
typedef Container underlying_container_type
 original intrusive container type for the bucket
 
typedef base_class::bucket_type bucket_type
 container type adapted for hash set
 
typedef bucket_type::value_type value_type
 value type stored in the set
 
typedef base_class::hash hash
 Hash functor.
 
typedef base_class::item_counter item_counter
 Item counter.
 
typedef base_class::resizing_policy resizing_policy
 Resizing policy.
 
typedef base_class::allocator_type allocator_type
 allocator type specified in options.
 
typedef base_class::mutex_policy mutex_policy
 Mutex policy.
 
- Protected Types inherited from cds::intrusive::StripedSet< Container, Options... >
typedef Container underlying_container_type
 original intrusive container type for the bucket
 
typedef cds::intrusive::striped_set::adapt< underlying_container_type, Options... >::type bucket_type
 container type adapted for hash set
 
typedef bucket_type::value_type value_type
 value type stored in the set
 
typedef options::hash hash
 Hash functor.
 
typedef options::item_counter item_counter
 Item counter.
 
typedef cds::opt::select_default< typename options::resizing_policy, typename bucket_type::default_resizing_policy >::type resizing_policy
 Resizing policy.
 
typedef options::allocator allocator_type
 allocator type specified in options.
 
typedef options::mutex_policy mutex_policy
 Mutex policy.
 
typedef cds::details::Allocator< bucket_type, allocator_typebucket_allocator
 bucket allocator type based on allocator_type
 
- Protected Member Functions inherited from cds::container::StripedSet< Container, Options... >
 StripedSet ()
 Default ctor. The initial capacity is 16.
 
 StripedSet (size_t nCapacity)
 Ctor with initial capacity specified. More...
 
 StripedSet (size_t nCapacity, resizing_policy const &resizingPolicy)
 Ctor with resizing policy (copy semantics) More...
 
 StripedSet (size_t nCapacity, resizing_policy &&resizingPolicy)
 Ctor with resizing policy (move semantics) More...
 
 ~StripedSet ()
 Destructor destroys internal data.
 
bool insert (Q const &val)
 Inserts new node. More...
 
bool insert (Q const &val, Func f)
 Inserts new node. More...
 
bool emplace (Args &&... args)
 Inserts data of type value_type constructed with std::forward<Args>(args)... More...
 
std::pair< bool, bool > update (Q const &val, Func func, bool bAllowInsert=true)
 Updates the node. More...
 
bool erase (Q const &key)
 Delete key from the set. More...
 
bool erase (Q const &key, Func f)
 Delete key from the set. More...
 
bool erase_with (Q const &key, Less pred)
 Deletes the item from the set using pred predicate for searching. More...
 
bool erase_with (Q const &key, Less 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 (Q const &val, Func f)
 Find the key val. More...
 
bool find_with (Q &val, Less pred, Func f)
 Find the key val using pred predicate. More...
 
bool find_with (Q const &val, Less pred, Func f)
 Find the key val using pred predicate. More...
 
bool contains (Q const &key)
 Checks whether the set contains key. More...
 
bool contains (Q const &key, Less pred)
 Checks whether the map contains key using pred predicate for searching. More...
 
void clear ()
 Clears the set. 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.
 
resizing_policyget_resizing_policy ()
 Returns resizing policy object.
 
resizing_policy const & get_resizing_policy () const
 Returns resizing policy (const version)
 
- Protected Member Functions inherited from cds::intrusive::StripedSet< Container, Options... >
 StripedSet ()
 Default ctor. The initial capacity is 16.
 
 StripedSet (size_t nCapacity)
 Ctor with initial capacity specified. More...
 
 StripedSet (size_t nCapacity, resizing_policy const &resizingPolicy)
 Ctor with resizing policy (copy semantics) More...
 
 StripedSet (size_t nCapacity, resizing_policy &&resizingPolicy)
 Ctor with resizing policy (move semantics) More...
 
 ~StripedSet ()
 Destructor destroys internal data.
 
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)
 Deletes the item from the set. More...
 
value_typeerase_with (Q const &val, Less pred)
 Deletes the item from the set using pred predicate for searching. More...
 
value_typeerase_with (Q const &val, Less 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 (Q const &val, Func f)
 Find the key val. More...
 
bool find_with (Q &val, Less pred, Func f)
 Find the key val using pred predicate. More...
 
bool find_with (Q const &val, Less pred, Func f)
 Find the key val using pred predicate. More...
 
bool contains (Q const &key)
 Checks whether the set contains key. More...
 
bool contains (Q const &key, Less pred)
 Checks whether the set contains key using pred predicate for searching. More...
 
void clear ()
 Clears the set. More...
 
void clear_and_dispose (Disposer disposer)
 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.
 
resizing_policyget_resizing_policy ()
 Returns resizing policy object.
 
resizing_policy const & get_resizing_policy () const
 Returns resizing policy (const version)
 
- Protected Attributes inherited from cds::intrusive::StripedSet< Container, Options... >
bucket_typem_Buckets
 Bucket table.
 
atomics::atomic< size_t > m_nBucketMask
 Bucket table size - 1. m_nBucketMask + 1 should be power of two.
 
item_counter m_ItemCounter
 Item counter.
 
hash m_Hash
 Hash functor.
 
mutex_policy m_MutexPolicy
 Mutex policy.
 
resizing_policy m_ResizingPolicy
 Resizing policy.
 
- Static Protected Attributes inherited from cds::intrusive::StripedSet< Container, Options... >
static const size_t c_nMinimalCapacity
 Minimal capacity.
 

Detailed Description

template<class Container, typename... Options>
class cds::container::StripedMap< Container, Options >

Striped hash map.

Source

  • [2008] Maurice Herlihy, Nir Shavit "The Art of Multiprocessor Programming"

Lock striping is very simple technique. The map consists of the bucket table and the array of locks. Initially, the capacity of lock array and bucket table is the same. When the map is resized, bucket table capacity will be doubled but lock array will not. The lock i protects each bucket j, where j = i mod L , where L - the size of lock array.

Template arguments:

  • Container - the container class that is used as bucket entry. The Container class should support an uniform interface described below.
  • Options - options

The StripedMap class does not exactly specify the type of container that should be used as a Container bucket. Instead, the class supports different container type for the bucket, for exampe, std::list, std::map and others.

Remember that StripedMap class algorithm ensures sequential blocking access to its bucket through the mutex type you specify among Options template arguments.

The Options are:

  • cds::opt::mutex_policy - concurrent access policy. Available policies: striped_set::striping, striped_set::refinable. Default is striped_set::striping.
  • cds::opt::hash - hash functor. Default option value see opt::v::hash_selector<opt::none> which selects default hash functor for your compiler.
  • cds::opt::compare - key comparison functor. No default functor is provided. If the option is not specified, the opt::less is used.
  • cds::opt::less - specifies binary predicate used for key comparison. Default is std::less<T>.
  • cds::opt::item_counter - item counter type. Default is atomicity::item_counter since some operation on the counter is performed without locks. Note that item counting is an essential part of the map algorithm, so dummy counter like as atomicity::empty_item_counter is not suitable.
  • cds::opt::allocator - the allocator type using for memory allocation of bucket table and lock array. Default is CDS_DEFAULT_ALLOCATOR.
  • cds::opt::resizing_policy - the resizing policy that is a functor that decides when to resize the hash map. Default option value depends on bucket container type: for sequential containers like std::list, std::vector the resizing policy is striped_set::load_factor_resizing<4> ; for other type of containers like std::map, std::unordered_map the resizing policy is striped_set::no_resizing. See available resizing policy. Note that the choose of resizing policy depends of Container type: for sequential containers like std::list, std::vector and so on, right choosing of the policy can significantly improve performance. For other, non-sequential types of Container (like a std::map) the resizing policy is not so important.
  • cds::opt::copy_policy - the copy policy which is used to copy items from the old map to the new one when resizing. The policy can be optionally used in adapted bucket container for performance reasons of resizing. The detail of copy algorithm depends on type of bucket container and explains below.

opt::compare or opt::less options are used only in some Container class for searching an item. opt::compare option has the highest priority: if opt::compare is specified, opt::less is not used.

You can pass other option that would be passed to adapt metafunction, see below.

Internal details

The StripedMap class cannot utilize the Container container specified directly, but only its adapted variant which supports an unified interface. Internally, the adaptation is made via striped_set::adapt metafunction that wraps bucket container and provides the unified bucket interface suitable for StripedMap. Such adaptation is completely transparent for you - you don't need to call adapt metafunction directly, StripedMap class's internal machinery itself invokes appropriate adapt metafunction to adjust your Container container class to StripedMap bucket's internal interface. All you need is to include a right header before striped_hash_map.h.

By default, striped_set::adapt<AnyContainer, Options...> metafunction does not make any wrapping to AnyContainer, so, the result striped_set::adapt<AnyContainer, Options...>::type is the same as AnyContainer. However, there are a lot of specializations of adapt for well-known containers, see table below. Any of this specialization wraps corresponding container making it suitable for the map's bucket. Remember, you should include the proper header file for adapt before striped_map.h.

Container .h-file for adapt Example Notes
std::list <cds/container/striped_map/std_list.h>
#include <cds/container/striped_map/std_list.h>
#include <cds/container/striped_hash_map.h>
std::list< std::pair< const Key, V > >,
> striped_map;
The type of values stored in the std::list must be std::pair< const Key, V > , where Key - key type, and V - value type The list is ordered by key Key. Template argument pack Options must contain cds::opt::less or cds::opt::compare for type Key stored in the list.
std::map <cds/container/striped_map/std_map.h>
#include <cds/container/striped_map/std_map.h>
#include <cds/container/striped_hash_map.h>
std::map< Key, T, std::less<Key> >
> striped_map;
std::unordered_map <cds/container/striped_map/std_hash_map.h>
#include <cds/container/striped_map/std_hash_map.h>
#include <cds/container/striped_hash_map.h>
std::unordered_map<
Key, T,
std::hash<Key>,
std::equal_to<Key>
>
> striped_map;
You should provide two different hash function h1 and h2 - one for std::unordered_map and other for StripedMap. For the best result, h1 and h2 must be orthogonal i.e. h1(X) != h2(X) for any value X of type Key.
boost::container::slist <cds/container/striped_map/boost_slist.h>
#include <cds/container/hash_smap/boost_slist.h>
#include <cds/container/striped_hash_map.h>
boost::container::slist< std::pair< const Key, T > >
> striped_map;
The type of values stored in the boost::container::slist must be std::pair< const Key, T > , where Key - key type, and T - value type. The list is ordered. Options must contain cds::opt::less or cds::opt::compare.
boost::container::list <cds/container/striped_map/boost_list.h>
#include <cds/container/striped_map/boost_list.h>
#include <cds/container/striped_hash_map.h>
boost::container::list< std::pair< const Key, T > >
> striped_map;
The type of values stored in the boost::container::list must be std::pair< const Key, T > , where Key - key type, and T - value type. The list is ordered. Options must contain cds::opt::less or cds::opt::compare.
boost::container::map <cds/container/striped_map/boost_map.h>
#include <cds/container/striped_map/boost_map.h>
#include <cds/container/striped_hash_map.h>
boost::container::map< Key, T, std::less<Key> >
> striped_map;
boost::container::flat_map <cds/container/striped_map/boost_flat_map.h>
#include <cds/container/striped_map/boost_flat_map.h>
#include <cds/container/striped_hash_map.h>
boost::container::flat_map< Key, T,
std::less< std::less<Key> >
>
> striped_map;
boost::unordered_map <cds/container/striped_map/boost_unordered_map.h>
#include <cds/container/striped_map/boost_unordered_map.h>
#include <cds/container/refinable_hash_map.h>
boost::unordered_map< Key, T, boost::hash<Key>, std::equal_to<Key> >
> refinable_map;

You can use another container type as map's bucket. Suppose, you have a container class MyBestContainer and you want to integrate it with StripedMap as bucket type. There are two possibility:

  • either your MyBestContainer class has native support of bucket's interface; in this case, you can use default striped_set::adapt metafunction;
  • or your MyBestContainer class does not support bucket's interface; it means you should develop a specialization cds::container::striped_set::adapt<MyBestContainer> metafunction providing necessary interface.

The striped_set::adapt< Container, Options... > metafunction has two template argument:

  • Container is the class that should be used as the bucket, for example, std::list< std::pair< Key, T > >.
  • Options pack is the options from StripedMap declaration. The adapt metafunction can use any option from Options for its internal use. For example, a compare option can be passed to adapt metafunction via Options argument of StripedMap declaration.

See striped_set::adapt metafunction for the description of interface that the bucket container must provide to be StripedMap compatible.

Copy policy There are three predefined copy policy:

  • cds::container::striped_set::copy_item - copy item from old bucket to new one when resizing using copy ctor. It is default policy for any compiler that do not support move semantics
  • cds::container::striped_set::move_item - move item from old bucket to new one when resizing using move semantics. It is default policy for any compiler that support move semantics. If compiler does not support move semantics, the move policy is the same as copy_item
  • cds::container::striped_set::swap_item - copy item from old bucket to new one when resizing using std::swap. Not all containers support this copy policy, see details in table below.

You can define your own copy policy specifically for your case. Note, right copy policy can significantly improve the performance of resizing.

Container Policies
  • std::list
  • boost::list
struct copy_item {
void operator()(
std::list< std::pair<const Key, T> >& list,
std::list<std::pair<const Key, T> >::iterator itInsert,
std::list<std::pair<const Key, T> >::iterator itWhat )
{
list.insert( itInsert, *itWhat );
}
}
// The type T stored in the list must be swappable
struct swap_item {
void operator()(
std::list< std::pair<const Key, T> >& list,
std::list<std::pair<const Key, T> >::iterator itInsert,
std::list<std::pair<const Key, T> >::iterator itWhat )
{
std::pair<Key, T> newVal( itWhat->first, T());
std::swap( list.insert( itInsert, newVal )->second, itWhat->second );
}
}
struct move_item {
void operator()(
std::list< std::pair<const Key, T> >& list,
std::list<std::pair<const Key, T> >::iterator itInsert,
std::list<std::pair<const Key, T> >::iterator itWhat )
{
list.insert( itInsert, std::move( *itWhat ));
}
}
  • std::map
  • std::unordered_map
  • boost::container::map
  • boost::container::flat_map
  • boost::unordered_map
struct copy_item {
void operator()( std::map< Key, T>& map, std::map<Key, T>::iterator itWhat )
{
map.insert( *itWhat );
}
}
struct swap_item {
void operator()( std::map< Key, T>& map, std::map<Key, T>::iterator itWhat )
{
std::swap(
map.insert(
std::map::value_type( itWhat->first, T())).first->second
, itWhat->second
));
}
}

T type must be swappable.

struct move_item {
void operator()( std::map< Key, T>& map, std::map<Key, T>::iterator itWhat )
{
map.insert( std::move( *itWhat ));
}
}
boost::container::slist
struct copy_item {
void operator()(
bc::slist< std::pair<const Key, T> >& list,
bc::slist<std::pair<const Key, T> >::iterator itInsert,
bc::slist<std::pair<const Key, T> >::iterator itWhat )
{
list.insert_after( itInsert, *itWhat );
}
}
// The type T stored in the list must be swappable
struct swap_item {
void operator()(
bc::slist< std::pair<const Key, T> >& list,
bc::slist<std::pair<const Key, T> >::iterator itInsert,
bc::slist<std::pair<const Key, T> >::iterator itWhat )
{
std::pair<Key, T> newVal( itWhat->first, T());
std::swap( list.insert( itInsert, newVal )->second, itWhat->second );
}
}
struct move_item {
void operator()(
bc::slist< std::pair<const Key, T> >& list,
bc::slist<std::pair<const Key, T> >::iterator itInsert,
bc::slist<std::pair<const Key, T> >::iterator itWhat )
{
list.insert_after( itInsert, std::move( *itWhat ));
}
}

Advanced functions

The library provides some advanced functions like erase_with(), find_with(), that cannot be supported by all underlying containers. The table below shows whether underlying container supports those functions (the sign "+" means "container supports the function"):

Container find_with erse_with
std::list + +
std::map - -
std::unordered_map - -
boost::container::slist + +
boost::container::list + +
boost::container::map - -
boost::container::flat_map - -
boost::unordered_map - -

Constructor & Destructor Documentation

◆ StripedMap() [1/3]

template<class Container , typename... Options>
cds::container::StripedMap< Container, Options >::StripedMap ( size_t  nCapacity)
inline

Ctor with initial capacity specified.

Parameters
nCapacityInitial size of bucket table and lock array. Must be power of two, the minimum is 16.

◆ StripedMap() [2/3]

template<class Container , typename... Options>
cds::container::StripedMap< Container, Options >::StripedMap ( size_t  nCapacity,
resizing_policy const &  resizingPolicy 
)
inline

Ctor with resizing policy (copy semantics)

This constructor initializes m_ResizingPolicy member with copy of resizingPolicy parameter

Parameters
nCapacityInitial size of bucket table and lock array. Must be power of two, the minimum is 16.
resizingPolicyResizing policy

◆ StripedMap() [3/3]

template<class Container , typename... Options>
cds::container::StripedMap< Container, Options >::StripedMap ( size_t  nCapacity,
resizing_policy &&  resizingPolicy 
)
inline

Ctor with resizing policy (move semantics)

This constructor initializes m_ResizingPolicy member moving resizingPolicy parameter Move semantics is used. Available only for the compilers that supports C++11 rvalue reference.

Parameters
nCapacityInitial size of bucket table and lock array. Must be power of two, the minimum is 16.
resizingPolicyResizing policy

Member Function Documentation

◆ bucket_count()

template<class Container , typename... Options>
size_t cds::container::StripedMap< Container, Options >::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<class Container , typename... Options>
template<typename K >
bool cds::container::StripedMap< Container, Options >::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<class Container , typename... Options>
template<typename K , typename Less , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type>
bool cds::container::StripedMap< Container, Options >::contains ( K const &  key,
Less  pred 
)
inline

Checks whether the set 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 set.

Note
This function is enabled if the compiler supports C++11 default template arguments for function template and the underlying container supports contains() feature.

◆ emplace()

template<class Container , typename... Options>
template<typename K , typename... Args>
bool cds::container::StripedMap< Container, Options >::emplace ( K &&  key,
Args &&...  args 
)
inline

For key key inserts data of type mapped_type created in-place from args.

Returns true if inserting successful, false otherwise.

◆ empty()

template<class Container , typename... Options>
bool cds::container::StripedMap< Container, Options >::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<class Container , typename... Options>
template<typename K >
bool cds::container::StripedMap< Container, Options >::erase ( K const &  key)
inline

Delete key from the map.

Return true if key is found and deleted, false otherwise

◆ erase() [2/2]

template<class Container , typename... Options>
template<typename K , typename Func >
bool cds::container::StripedMap< Container, Options >::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

◆ erase_with() [1/2]

template<class Container , typename... Options>
template<typename K , typename Less , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type>
bool cds::container::StripedMap< Container, Options >::erase_with ( K const &  key,
Less  pred 
)
inline

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

The function is an analog of erase(K const&) but pred is used for key comparing. Less functor has the interface like std::less. pred must imply the same element order as the comparator used for building the map.

Note
This function is enabled if the compiler supports C++11 default template arguments for function template and the underlying container supports erase_with feature.

◆ erase_with() [2/2]

template<class Container , typename... Options>
template<typename K , typename Less , typename Func , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type>
bool cds::container::StripedMap< Container, Options >::erase_with ( K const &  key,
Less  pred,
Func  f 
)
inline

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

The function is an analog of erase(K const&, Func) but pred is used for key comparing. Less functor has the interface like std::less. pred must imply the same element order as the comparator used for building the map.

Note
This function is enabled if the compiler supports C++11 default template arguments for function template and the underlying container supports erase_with feature.

◆ find()

template<class Container , typename... Options>
template<typename K , typename Func >
bool cds::container::StripedMap< Container, Options >::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<class Container , typename... Options>
template<typename K , typename Less , typename Func , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type>
bool cds::container::StripedMap< Container, Options >::find_with ( K const &  key,
Less  pred,
Func  f 
)
inline

Find the key val using pred predicate.

The function is an analog of find(K const&, Func) but pred is used for key comparing Less has the interface like std::less. pred must imply the same element order as the comparator used for building the set.

Note
This function is enabled if the compiler supports C++11 default template arguments for function template and the underlying container supports find_with feature.

◆ insert() [1/2]

template<class Container , typename... Options>
template<typename K >
bool cds::container::StripedMap< Container, Options >::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<class Container , typename... Options>
template<typename K , typename V >
bool cds::container::StripedMap< Container, Options >::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 mapped_type should be constructible from val of type V.

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

◆ insert_with()

template<class Container , typename... Options>
template<typename K , typename Func >
bool cds::container::StripedMap< Container, Options >::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 mapped_type is heavyweight and it is preferable that the initialization should be completed only if inserting is successful.

◆ lock_count()

template<class Container , typename... Options>
size_t cds::container::StripedMap< Container, Options >::lock_count ( ) const
inline

Returns lock array size.

The lock array size is constant.

◆ update()

template<class Container , typename... Options>
template<typename K , typename Func >
std::pair<bool, bool> cds::container::StripedMap< Container, Options >::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 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 - item of the map

Returns std::pair<bool, bool> where first is true if operation is successful, second is true if new item has been added or false if the item with key already is in the map.


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:29 by Doxygen 1.8.13