cds  2.2.0
cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits > Class Template Reference

Bronson et al AVL-tree (RCU specialization for pointers) More...

#include <cds/container/bronson_avltree_map_rcu.h>

Inheritance diagram for cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >:
cds::container::BronsonAVLTreeMap< 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 Traits traits
 Traits template parameter.
 
typedef implementation_defined key_comparator
 key compare functor based on Traits::compare and Traits::less
 
typedef traits::item_counter item_counter
 Item counting policy.
 
typedef traits::memory_model memory_model
 Memory ordering, see cds::opt::memory_model option.
 
typedef traits::node_allocator node_allocator_type
 allocator for maintaining internal nodes
 
typedef traits::stat stat
 internal statistics
 
typedef traits::rcu_check_deadlock rcu_check_deadlock
 Deadlock checking policy.
 
typedef traits::back_off back_off
 Back-off strategy.
 
typedef traits::disposer disposer
 Value disposer.
 
typedef traits::sync_monitor sync_monitor
 Synchronization monitor type for node-level locking
 
typedef cds::urcu::exempt_ptr< gc, T, T, disposer, void > exempt_ptr
 Returned pointer to mapped_type of extracted node.
 
typedef gc::scoped_lock rcu_lock
 RCU scoped lock.
 

Public Member Functions

 BronsonAVLTreeMap ()
 Creates empty map.
 
 ~BronsonAVLTreeMap ()
 Destroys the map.
 
template<typename K >
bool insert (K const &key, mapped_type pVal)
 Inserts new node. More...
 
template<typename K >
std::pair< bool, bool > update (K const &key, mapped_type pVal, bool bInsert=true)
 Updates the value for key. 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 a value with minimal key from the map. More...
 
template<typename Func >
exempt_ptr extract_min (Func f)
 Extracts minimal key and corresponding value. More...
 
std::enable_if< std::is_copy_assignable< key_type >::value, exempt_ptr >::type extract_min_key (key_type &min_key)
 Extracts minimal key and corresponding value. More...
 
exempt_ptr extract_max ()
 Extracts a value with maximal key from the tree. More...
 
template<typename Func >
exempt_ptr extract_max (Func f)
 Extracts the maximal key and corresponding value. More...
 
std::enable_if< std::is_copy_assignable< key_type >::value, exempt_ptr >::type extract_max_key (key_type &max_key)
 Extracts the maximal key and corresponding value. 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...
 
void clear ()
 Clears the tree (thread safe, not atomic) More...
 
void unsafe_clear ()
 Clears the tree (not thread safe) More...
 
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.
 
sync_monitormonitor ()
 Returns reference to sync_monitor object.
 
bool check_consistency () const
 Checks internal consistency (not atomic, not thread-safe) More...
 
template<typename Func >
bool check_consistency (Func f) const
 Checks internal consistency (not atomic, not thread-safe) More...
 

Static Public Attributes

static constexpr bool const c_bRelaxedInsert = traits::relaxed_insert
 Enabled or disabled relaxed insertion.
 
static constexpr const bool c_bExtractLockExternal = false
 Group of extract_xxx functions does not require external locking.
 

Detailed Description

template<typename RCU, typename Key, typename T, typename Traits = bronson_avltree::traits>
class cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >

Bronson et al AVL-tree (RCU specialization for pointers)

This is the specialization of RCU-based Bronson et al AVL-tree for "key -> value pointer" map. This specialization stores the pointer to user-allocated values instead of the copy of the value. When a tree node is removed, the algorithm does not free the value pointer directly, instead, it call the disposer functor provided by Traits template parameter.

Template arguments:

  • RCU - one of RCU type
  • Key - key type
  • T - value type to be stored in tree's nodes. Note, the specialization stores the pointer to user-allocated value, not the copy.
  • Traits - tree traits, default is bronson_avltree::traits It is possible to declare option-based tree with bronson_avltree::make_traits metafunction instead of Traits template argument.
Note
Before including <cds/container/bronson_avltree_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() [1/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
bool cds::container::BronsonAVLTreeMap< 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.

§ check_consistency() [2/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename Func >
bool cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::check_consistency ( Func  f) const
inline

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

The debugging function to check internal consistency of the tree. The functor Func is called if a violation of internal tree structure is found:

struct functor {
void operator()( size_t nLevel, size_t hLeft, size_t hRight );
};

where

  • nLevel - the level where the violation is found
  • hLeft - the height of left subtree
  • hRight - the height of right subtree

The functor is called for each violation found.

§ clear()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
void cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::clear ( )
inline

Clears the tree (thread safe, not atomic)

The function unlink all items from the tree. The function is thread safe but not atomic: in multi-threaded environment with parallel insertions this sequence

set.clear();
assert( set.empty());

the assertion could be raised.

For each node the disposer will be called after unlinking.

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

§ contains() [1/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K >
bool cds::container::BronsonAVLTreeMap< 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<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Less >
bool cds::container::BronsonAVLTreeMap< 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. Less must imply the same element order as the comparator used for building the set.

§ erase() [1/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K >
bool cds::container::BronsonAVLTreeMap< 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<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Func >
bool cds::container::BronsonAVLTreeMap< 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 functor {
void operator()( key_type const& key, std::remove_pointer<mapped_type>::type& val) { ... }
};

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<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Less >
bool cds::container::BronsonAVLTreeMap< 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<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Less , typename Func >
bool cds::container::BronsonAVLTreeMap< 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<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename Q >
exempt_ptr cds::container::BronsonAVLTreeMap< 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 a value 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 value found. The disposer will be implicitly invoked when the returned object is destroyed or when its release() member function is called.

§ extract_max() [1/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
exempt_ptr cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_max ( )
inline

Extracts a value with maximal key from the tree.

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

Note that the function returns only the value for maximal key. To retrieve its key use extract_max( Func ) member function.

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.

§ extract_max() [2/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename Func >
exempt_ptr cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_max ( Func  f)
inline

Extracts the maximal key and corresponding value.

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

Func functor is used to store maximal key. Func has the following signature:

struct functor {
void operator()( key_type const& key );
};

If the tree is empty, f is not called. Otherwise, it is called with maximal key, the pointer to corresponding value is returned as 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.

§ extract_max_key()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
std::enable_if< std::is_copy_assignable<key_type>::value, exempt_ptr >::type cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_max_key ( key_type max_key)
inline

Extracts the maximal key and corresponding value.

This function is a shortcut for the following call:

exempt_ptr xp = theTree.extract_max( [&key]( key_type const& k ) { key = k; } );

key_type should be copy-assignable. The copy of maximal key is returned in max_key argument.

§ extract_min() [1/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
exempt_ptr cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_min ( )
inline

Extracts a value with minimal key from the map.

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

Note that the function returns only the value for minimal key. To retrieve its key use extract_min( Func ) member function.

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_min() [2/2]

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename Func >
exempt_ptr cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_min ( Func  f)
inline

Extracts minimal key and corresponding value.

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

Func functor is used to store minimal key. Func has the following signature:

struct functor {
void operator()( key_type const& key );
};

If the tree is empty, f is not called. Otherwise, it is called with minimal key, the pointer to corresponding value is returned as 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_min_key()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
std::enable_if< std::is_copy_assignable<key_type>::value, exempt_ptr >::type cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::extract_min_key ( key_type min_key)
inline

Extracts minimal key and corresponding value.

This function is a shortcut for the following call:

exempt_ptr xp = theTree.extract_min( [&key]( key_type const& k ) { key = k; } );

key_type should be copy-assignable. The copy of minimal key is returned in min_key argument.

§ extract_with()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename Q , typename Less >
exempt_ptr cds::container::BronsonAVLTreeMap< 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. pred must imply the same element order as the comparator used for building the tree.

§ find()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Func >
bool cds::container::BronsonAVLTreeMap< 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()( key_type const& key, std::remove_pointer< mapped_type )::type& item );
};

where item is the item found. The functor is called under node-level lock.

The function applies RCU lock internally.

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

§ find_with()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K , typename Less , typename Func >
bool cds::container::BronsonAVLTreeMap< 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.

§ insert()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K >
bool cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::insert ( K const &  key,
mapped_type  pVal 
)
inline

Inserts new node.

The key_type should be constructible from a value of type K.

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

Returns true if inserting successful, false otherwise.

§ size()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
size_t cds::container::BronsonAVLTreeMap< 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.

§ unsafe_clear()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
void cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::unsafe_clear ( )
inline

Clears the tree (not thread safe)

This function is not thread safe and may be called only when no other thread deals with the tree. The function is used in the tree destructor.

§ update()

template<typename RCU , typename Key , typename T , typename Traits = bronson_avltree::traits>
template<typename K >
std::pair<bool, bool> cds::container::BronsonAVLTreeMap< cds::urcu::gc< RCU >, Key, T *, Traits >::update ( K const &  key,
mapped_type  pVal,
bool  bInsert = true 
)
inline

Updates the value for key.

The operation performs inserting or updating the value for key with lock-free manner. If bInsert is false, only updating of existing node is possible.

If key is not found and inserting is allowed (i.e. bInsert is true), then the new node created from key will be inserted into the map; note that in this case the key_type should be constructible from type K. Otherwise, the value for key will be changed to pVal.

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

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


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

cds 2.2.0 Developed by Maxim Khizhinsky aka khizmax 2007 - 2017
Autogenerated Wed Jan 4 2017 08:49:33 by Doxygen 1.8.12