cds  2.3.2
cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits > Class Template Reference

Map based on Ellen's et al binary search tree (RCU specialization) More...

#include <cds/container/ellen_bintree_map_rcu.h>

Inheritance diagram for cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >:
cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >

Public Types

typedef cds::urcu::gc< RCU > gc
 RCU Garbage collector.
 
typedef Key key_type
 type of a key stored in the map
 
typedef T mapped_type
 type of value stored in the map
 
typedef std::pair< key_type const, mapped_typevalue_type
 Key-value pair stored in leaf node of the mp.
 
typedef Traits traits
 Traits template parameter.
 
typedef implementation_defined key_comparator
 key compare functor based on Traits::compare and Traits::less
 
typedef base_class::item_counter item_counter
 Item counting policy.
 
typedef base_class::memory_model memory_model
 Memory ordering, see cds::opt::memory_model option.
 
typedef base_class::node_allocator node_allocator_type
 allocator for maintaining internal node
 
typedef base_class::stat stat
 internal statistics
 
typedef base_class::rcu_check_deadlock rcu_check_deadlock
 Deadlock checking policy.
 
typedef traits::copy_policy copy_policy
 key copy policy
 
typedef traits::back_off back_off
 Back-off strategy.
 
typedef traits::allocator allocator_type
 Allocator for leaf nodes.
 
typedef base_class::node_allocator node_allocator
 Internal node allocator.
 
typedef base_class::update_desc_allocator update_desc_allocator
 Update descriptor allocator.
 
typedef gc::scoped_lock rcu_lock
 RCU scoped lock.
 
using exempt_ptr = cds::urcu::exempt_ptr< gc, leaf_node, value_type, typename maker::intrusive_traits::disposer, cds::urcu::details::conventional_exempt_member_cast< leaf_node, value_type > >
 pointer to extracted node
 
- Public Types inherited from cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >
typedef cds::urcu::gc< RCU > gc
 RCU Garbage collector.
 
typedef Key key_type
 type of a key stored in internal nodes; key is a part of value_type
 
typedef T value_type
 type of value stored in the binary tree
 
typedef Traits traits
 Traits template parameter.
 
typedef traits::hook hook
 hook type
 
typedef hook::node_type node_type
 node type
 
typedef traits::disposer disposer
 leaf node disposer
 
typedef traits::back_off back_off
 back-off strategy
 
using exempt_ptr = cds::urcu::exempt_ptr< gc, value_type, value_type, disposer, void >
 pointer to extracted node
 
typedef implementation_defined key_comparator
 key compare functor based on Traits::compare and Traits::less
 
typedef get_node_traits< value_type, node_type, hook >::type node_traits
 Node traits.
 
typedef traits::item_counter item_counter
 Item counting policy used.
 
typedef traits::memory_model memory_model
 Memory ordering. See cds::opt::memory_model option.
 
typedef traits::stat stat
 internal statistics type
 
typedef traits::rcu_check_deadlock rcu_check_deadlock
 Deadlock checking policy.
 
typedef traits::key_extractor key_extractor
 key extracting functor
 
typedef traits::node_allocator node_allocator
 Internal node allocator.
 
typedef traits::update_desc_allocator update_desc_allocator
 Update descriptor allocator.
 
typedef gc::scoped_lock rcu_lock
 RCU scoped lock.
 

Public Member Functions

 EllenBinTreeMap ()
 Default constructor.
 
 ~EllenBinTreeMap ()
 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 (K const &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 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 >
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 >
bool erase_with (K const &key, Less pred, Func f)
 Deletes the item from the map using pred predicate for searching. More...
 
exempt_ptr extract_min ()
 Extracts an item with minimal key from the map. More...
 
exempt_ptr extract_max ()
 Extracts an item with maximal key from the map. More...
 
template<typename Q >
exempt_ptr extract (Q const &key)
 Extracts an item from the map. More...
 
template<typename Q , typename Less >
exempt_ptr extract_with (Q const &key, Less pred)
 Extracts an item from the map using pred 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 >
bool find_with (K const &key, Less pred, Func f)
 Finds the key val using pred predicate for searching. More...
 
template<typename K >
bool contains (K const &key)
 Checks whether the map contains key. More...
 
template<typename K , typename Less >
bool contains (K const &key, Less pred)
 Checks whether the map contains key using pred predicate for searching. More...
 
template<typename Q >
value_typeget (Q const &key) const
 Finds key and return the item found. More...
 
template<typename Q , typename Less >
value_typeget_with (Q const &key, Less pred) const
 Finds key with pred predicate and return the item found. More...
 
void clear ()
 Clears the map.
 
bool empty () const
 Checks if the map is empty.
 
size_t size () const
 Returns item count in the map. More...
 
stat const & statistics () const
 Returns const reference to internal statistics.
 
bool check_consistency () const
 Checks internal consistency (not atomic, not thread-safe) More...
 
- Public Member Functions inherited from cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >
 EllenBinTree ()
 Default constructor.
 
 ~EllenBinTree ()
 Clears the tree.
 
bool insert (value_type &val)
 Inserts new node. More...
 
template<typename Func >
bool insert (value_type &val, Func f)
 Inserts new node. More...
 
template<typename Func >
std::pair< bool, bool > update (value_type &val, Func func, bool bAllowInsert=true)
 Updates the node. More...
 
bool unlink (value_type &val)
 Unlinks the item val from the tree. More...
 
template<typename Q >
bool erase (const Q &key)
 Deletes the item from the tree. More...
 
template<typename Q , typename Less >
bool erase_with (const Q &key, Less pred)
 Delete the item from the tree with comparing functor pred. More...
 
template<typename Q , typename Func >
bool erase (Q const &key, Func f)
 Deletes the item from the tree. More...
 
template<typename Q , typename Less , typename Func >
bool erase_with (Q const &key, Less pred, Func f)
 Delete the item from the tree with comparing functor pred. More...
 
exempt_ptr extract_min ()
 Extracts an item with minimal key from the tree. More...
 
exempt_ptr extract_max ()
 Extracts an item with maximal key from the tree. More...
 
template<typename Q >
exempt_ptr extract (Q const &key)
 Extracts an item from the tree. More...
 
template<typename Q , typename Less >
exempt_ptr extract_with (Q const &key, Less pred)
 Extracts an item from the set using pred for searching. More...
 
template<typename Q >
bool contains (Q const &key) const
 Checks whether the set contains key. More...
 
template<typename Q , typename Less >
bool contains (Q const &key, Less pred) const
 Checks whether the set contains key using pred predicate for searching. More...
 
template<typename Q , typename Func >
bool find (Q &key, Func f) const
 Finds the key key. More...
 
template<typename Q , typename Less , typename Func >
bool find_with (Q &key, Less pred, Func f) const
 Finds the key key with comparing functor pred. More...
 
template<typename Q >
value_typeget (Q const &key) const
 Finds key and return the item found. More...
 
template<typename Q , typename Less >
value_typeget_with (Q const &key, Less pred) const
 Finds key with pred predicate and return the item found. More...
 
bool empty () const
 Checks if the tree is empty.
 
void clear ()
 Clears the tree (thread safe, not atomic) More...
 
void unsafe_clear ()
 Clears the tree (not thread safe) More...
 
size_t size () const
 Returns item count in the tree. More...
 
stat const & statistics () const
 Returns const reference to internal statistics.
 
bool check_consistency () const
 Checks internal consistency (not atomic, not thread-safe) More...
 

Static Public Attributes

static constexpr const bool c_bExtractLockExternal = base_class::c_bExtractLockExternal
 Group of extract_xxx functions do not require external locking.
 
- Static Public Attributes inherited from cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >
static constexpr const bool c_bExtractLockExternal = false
 Group of extract_xxx functions do not require external locking.
 

Additional Inherited Members

- Protected Attributes inherited from cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >
item_counter m_ItemCounter
 item counter
 
stat m_Stat
 internal statistics
 

Detailed Description

template<class RCU, typename Key, typename T, class Traits = ellen_bintree::traits>
class cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >

Map based on Ellen's et al binary search tree (RCU specialization)

Source:

  • [2010] F.Ellen, P.Fatourou, E.Ruppert, F.van Breugel "Non-blocking Binary Search Tree"

EllenBinTreeMap is an unbalanced leaf-oriented binary search tree that implements the map abstract data type. Nodes maintains child pointers but not parent pointers. Every internal node has exactly two children, and all data of type std::pair<Key const, T> currently in the tree are stored in the leaves. Internal nodes of the tree are used to direct find operation along the path to the correct leaf. The keys (of Key type) stored in internal nodes may or may not be in the map. Unlike EllenBinTreeSet keys are not a part of T type. The map can be represented as a set containing std::pair< Key const, T> values.

Due to extract_min and extract_max member functions the EllenBinTreeMap can act as a priority queue. In this case you should provide unique compound key, for example, the priority value plus some uniformly distributed random value.

Warning
Recall the tree is unbalanced. The complexity of operations is O(log N) for uniformly distributed random keys, but in the worst case the complexity is O(N).
Note
In the current implementation we do not use helping technique described in original paper. So, the current implementation is near to fine-grained lock-based tree. Helping will be implemented in future release

Template arguments :

Note
Before including <cds/container/ellen_bintree_map_rcu.h> you should include appropriate RCU header file, see RCU type for list of existing RCU class and corresponding header files.

Member Function Documentation

◆ check_consistency()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::check_consistency ( ) const
inline

Checks internal consistency (not atomic, not thread-safe)

The debugging function to check internal consistency of the tree.

◆ contains() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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.

The function applies RCU lock internally.

◆ contains() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Less >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::contains ( K const &  key,
Less  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 and should meet Predicate requirements. Less must imply the same element order as the comparator used for building the set.

◆ emplace()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename... Args>
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::emplace ( K &&  key,
Args &&...  args 
)
inline

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

Returns true if inserting successful, false otherwise.

RCU synchronize() method can be called. RCU should not be locked.

◆ erase() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::erase ( K const &  key)
inline

Delete key from the map.

RCU synchronize() method can be called. RCU should not be locked.

Return true if key is found and deleted, false otherwise

◆ erase() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Func >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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) { ... }
};

RCU synchronize method can be called. RCU should not be locked.

Return true if key is found and deleted, false otherwise

◆ erase_with() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Less >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::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. Less must imply the same element order as the comparator used for building the map.

◆ erase_with() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Less , typename Func >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::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. Less must imply the same element order as the comparator used for building the map.

◆ extract()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q >
exempt_ptr cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::extract ( Q const &  key)
inline

Extracts an item from the map.

The function searches an item with key equal to key in the tree, unlinks it, and returns exempt_ptr pointer to an item found. If key is not found the function returns an empty exempt_ptr.

RCU synchronize method can be called. RCU should NOT be locked. The function does not destroy the item found. The dealloctor will be implicitly invoked when the returned object is destroyed or when its release() member function is called.

◆ extract_max()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
exempt_ptr cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::extract_max ( )
inline

Extracts an item with maximal key from the map.

Returns exempt_ptr pointer to the rightmost item. If the set is empty, returns empty exempt_ptr.

Note
Due the concurrent nature of the map, the function extracts nearly maximal key. It means that the function gets rightmost leaf of the tree and tries to unlink it. During unlinking, a concurrent thread may insert an item with key great than leftmost item's key. So, the function returns the item with maximum key at the moment of tree traversing.

RCU synchronize method can be called. RCU should NOT be locked. The function does not free the item. The deallocator will be implicitly invoked when the returned object is destroyed or when its release() is called.

Note
Before reusing result object you should call its release() method.

◆ extract_min()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
exempt_ptr cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::extract_min ( )
inline

Extracts an item with minimal key from the map.

Returns exempt_ptr pointer to the leftmost item. If the set is empty, returns empty exempt_ptr.

Note
Due the concurrent nature of the map, the function extracts nearly minimum key. It means that the function gets leftmost leaf of the tree and tries to unlink it. During unlinking, a concurrent thread may insert an item with key less than leftmost item's key. So, the function returns the item with minimum key at the moment of tree traversing.

RCU synchronize method can be called. RCU should NOT be locked. The function does not free the item. The deallocator will be implicitly invoked when the returned object is destroyed or when its release() member function is called.

◆ extract_with()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Less >
exempt_ptr cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::extract_with ( Q const &  key,
Less  pred 
)
inline

Extracts an item from the map using pred for searching.

The function is an analog of extract(Q const&) but pred is used for key compare. Less has the interface like std::less and should meet predicate requirements. pred must imply the same element order as the comparator used for building the map.

◆ find()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Func >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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 applies RCU lock internally.

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

◆ find_with()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Less , typename Func >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::find_with ( K const &  key,
Less  pred,
Func  f 
)
inline

Finds the key val using pred predicate for searching.

The function is an analog of find(K const&, Func) 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.

◆ get()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q >
value_type* cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::get ( Q const &  key) const
inline

Finds key and return the item found.

The function searches the item with key equal to key and returns the pointer to item found. If key is not found it returns nullptr.

RCU should be locked before call the function. Returned pointer is valid while RCU is locked.

◆ get_with()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Less >
value_type* cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::get_with ( Q const &  key,
Less  pred 
) const
inline

Finds key with pred predicate and return the item found.

The function is an analog of get(Q const&) but pred is used for comparing the keys.

Less functor has the semantics like std::less but should take arguments of type key_type and Q in any order. pred must imply the same element order as the comparator used for building the map.

◆ insert() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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.
  • The mapped_type should be default-constructible.

RCU synchronize() can be called. RCU should not be locked.

Returns true if inserting successful, false otherwise.

◆ insert() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename V >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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.

RCU synchronize() method can be called. RCU should not be locked.

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

◆ insert_with()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Func >
bool cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::insert_with ( K const &  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.

RCU synchronize() method can be called. RCU should not be locked.

◆ size()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
size_t cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits >::size ( ) const
inline

Returns item count in the map.

Only leaf nodes containing user data are counted.

The value returned depends on item counter type provided by Traits template parameter. If it is atomicity::empty_item_counter this function always returns 0.

The function is not suitable for checking the tree emptiness, use empty() member function for this purpose.

◆ update()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename K , typename Func >
std::pair<bool, bool> cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, 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 the item val is not found in the map, then val 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 - item of the map

The functor may change any fields of the item.second that is mapped_type; however, func must guarantee that during changing no any other modifications could be made on this item by concurrent threads.

RCU synchronize() method can be called. RCU should not be locked.

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.

Warning
See insert item troubleshooting

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