cds  2.3.2
cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits > Class Template Reference

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

#include <cds/intrusive/ellen_bintree_rcu.h>

Inheritance diagram for cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >:
cds::container::EllenBinTreeMap< cds::urcu::gc< RCU >, Key, T, Traits > cds::container::EllenBinTreeSet< 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 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

 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 = false
 Group of extract_xxx functions do not require external locking.
 

Protected Attributes

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::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >

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"

EllenBinTree is an unbalanced leaf-oriented binary search tree that implements the set abstract data type. Nodes maintains child pointers but not parent pointers. Every internal node has exactly two children, and all data of type 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 set. Key type is a subset of T type. There should be exactly defined a key extracting functor for converting object of type T to object of type Key.

Due to extract_min and extract_max member functions the EllenBinTree 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.

Attention
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 the original paper. Instead of helping, when a thread encounters a concurrent operation it just spins waiting for the operation done. Such solution allows greatly simplify the implementation of tree.

Template arguments:

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

Predicate requirements

Traits::less, Traits::compare and other predicates using with member fuctions should accept at least parameters of type T and Key in any combination. For example, for Foo struct with std::string key field the appropiate less functor is:

struct Foo: public cds::intrusive::ellen_bintree::node< ... >
{
std::string m_strKey;
...
};
struct less {
bool operator()( Foo const& v1, Foo const& v2 ) const
{ return v1.m_strKey < v2.m_strKey ; }
bool operator()( Foo const& v, std::string const& s ) const
{ return v.m_strKey < s ; }
bool operator()( std::string const& s, Foo const& v ) const
{ return s < v.m_strKey ; }
// Support comparing std::string and char const *
bool operator()( std::string const& s, char const * p ) const
{ return s.compare(p) < 0 ; }
bool operator()( Foo const& v, char const * p ) const
{ return v.m_strKey.compare(p) < 0 ; }
bool operator()( char const * p, std::string const& s ) const
{ return s.compare(p) > 0; }
bool operator()( char const * p, Foo const& v ) const
{ return v.m_strKey.compare(p) > 0; }
};

Usage

Suppose we have the following Foo struct with string key type:

struct Foo {
std::string m_strKey ; // The key
//... // other non-key data
};

We want to utilize RCU-based cds::intrusive::EllenBinTree set for Foo data. We may use base hook or member hook. Consider base hook variant. First, we need deriving Foo struct from cds::intrusive::ellen_bintree::node:

#include <cds/urcu/general_buffered.h>
#include <cds/intrusive/ellen_bintree_rcu.h>
// RCU type we use
typedef cds::urcu::gc< cds::urcu::general_buffered<> > gpb_rcu;
struct Foo: public cds::intrusive:ellen_bintree::node< gpb_rcu >
{
std::string m_strKey ; // The key
//... // other non-key data
};

Second, we need to implement auxiliary structures and functors:

  • key extractor functor for extracting the key from Foo object. Such functor is necessary because the tree internal nodes store the keys.
  • less predicate. We want our set should accept std::string and char const * parameters for searching, so our less predicate will not be trivial, see below.
  • item counting feature: we want our set's size() member function returns actual item count.
// Key extractor functor
struct my_key_extractor
{
void operator ()( std::string& key, Foo const& src ) const
{
key = src.m_strKey;
}
};
// Less predicate
struct my_less {
bool operator()( Foo const& v1, Foo const& v2 ) const
{ return v1.m_strKey < v2.m_strKey ; }
bool operator()( Foo const& v, std::string const& s ) const
{ return v.m_strKey < s ; }
bool operator()( std::string const& s, Foo const& v ) const
{ return s < v.m_strKey ; }
// Support comparing std::string and char const *
bool operator()( std::string const& s, char const * p ) const
{ return s.compare(p) < 0 ; }
bool operator()( Foo const& v, char const * p ) const
{ return v.m_strKey.compare(p) < 0 ; }
bool operator()( char const * p, std::string const& s ) const
{ return s.compare(p) > 0; }
bool operator()( char const * p, Foo const& v ) const
{ return v.m_strKey.compare(p) > 0; }
};
// Tree traits for our set
// It is necessary to specify only those typedefs that differ from
// cds::intrusive::ellen_bintree::traits defaults.
struct set_traits: public cds::intrusive::ellen_bintree::traits
{
typedef my_key_extractor key_extractor;
typedef my_less less;
};

Now we declare EllenBinTree set and use it:

Instead of declaring set_traits type traits we can use option-based syntax with ellen_bintree::make_traits metafunction, for example:

typedef cds::intrusive::EllenBinTree< gpb_rcu, std::string, Foo,
cds::opt::hook< cds::intrusive::ellen_bintree::base_hook< cds::opt::gc<gpb_rcu> > >
>::type
> set_type2;

Functionally, set_type and set_type2 are equivalent.

Member-hooked tree

Sometimes, we cannot use base hook, for example, when the Foo structure is external. In such case we can use member hook feature.

#include <cds/urcu/general_buffered.h>
#include <cds/intrusive/ellen_bintree_rcu.h>
// Struct Foo is external and its declaration cannot be modified.
struct Foo {
std::string m_strKey ; // The key
//... // other non-key data
};
// RCU type we use
typedef cds::urcu::gc< cds::urcu::general_buffered<> > gpb_rcu;
// Foo wrapper
struct MyFoo
{
Foo m_foo;
cds::intrusive:ellen_bintree::node< gpb_rcu > set_hook; // member hook
};
// Key extractor functor
struct member_key_extractor
{
void operator ()( std::string& key, MyFoo const& src ) const
{
key = src.m_foo.m_strKey;
}
};
// Less predicate
struct member_less {
bool operator()( MyFoo const& v1, MyFoo const& v2 ) const
{ return v1.m_foo.m_strKey < v2.m_foo.m_strKey ; }
bool operator()( MyFoo const& v, std::string const& s ) const
{ return v.m_foo.m_strKey < s ; }
bool operator()( std::string const& s, MyFoo const& v ) const
{ return s < v.m_foo.m_strKey ; }
// Support comparing std::string and char const *
bool operator()( std::string const& s, char const * p ) const
{ return s.compare(p) < 0 ; }
bool operator()( MyFoo const& v, char const * p ) const
{ return v.m_foo.m_strKey.compare(p) < 0 ; }
bool operator()( char const * p, std::string const& s ) const
{ return s.compare(p) > 0; }
bool operator()( char const * p, MyFoo const& v ) const
{ return v.m_foo.m_strKey.compare(p) > 0; }
};
// Tree traits for our member-based set
struct member_set_traits: public cds::intrusive::ellen_bintree::traits
{
typedef member_key_extractor key_extractor;
typedef member_less less;
};
// Tree containing MyFoo objects
member_set_type theMemberSet;

Multiple containers

Sometimes we need that our Foo struct should be used in several different containers. Suppose, Foo struct has two key fields:

struct Foo {
std::string m_strKey ; // string key
int m_nKey ; // int key
//... // other non-key data fields
};

We want to build two intrusive EllenBinTree sets: one indexed on Foo::m_strKey field, another indexed on Foo::m_nKey field. To decide such case we should use a tag option for tree's hook:

#include <cds/urcu/general_buffered.h>
#include <cds/intrusive/ellen_bintree_rcu.h>
// RCU type we use
typedef cds::urcu::gc< cds::urcu::general_buffered<> > gpb_rcu;
// Declare tag structs
struct int_tag ; // int key tag
struct string_tag ; // string key tag
// Foo struct is derived from two ellen_bintree::node class
// with different tags
struct Foo
: public cds::intrusive::ellen_bintree::node< gpb_rcu, cds::opt::tag< string_tag >>
, public cds::intrusive::ellen_bintree::node< gpb_rcu, cds::opt::tag< int_tag >>
{
std::string m_strKey ; // string key
int m_nKey ; // int key
//... // other non-key data fields
};
// String key extractor functor
struct string_key_extractor
{
void operator ()( std::string& key, Foo const& src ) const
{
key = src.m_strKey;
}
};
// Int key extractor functor
struct int_key_extractor
{
void operator ()( int& key, Foo const& src ) const
{
key = src.m_nKey;
}
};
// String less predicate
struct string_less {
bool operator()( Foo const& v1, Foo const& v2 ) const
{ return v1.m_strKey < v2.m_strKey ; }
bool operator()( Foo const& v, std::string const& s ) const
{ return v.m_strKey < s ; }
bool operator()( std::string const& s, Foo const& v ) const
{ return s < v.m_strKey ; }
// Support comparing std::string and char const *
bool operator()( std::string const& s, char const * p ) const
{ return s.compare(p) < 0 ; }
bool operator()( Foo const& v, char const * p ) const
{ return v.m_strKey.compare(p) < 0 ; }
bool operator()( char const * p, std::string const& s ) const
{ return s.compare(p) > 0; }
bool operator()( char const * p, Foo const& v ) const
{ return v.m_strKey.compare(p) > 0; }
};
// Int less predicate
struct int_less {
bool operator()( Foo const& v1, Foo const& v2 ) const
{ return v1.m_nKey < v2.m_nKey ; }
bool operator()( Foo const& v, int n ) const
{ return v.m_nKey < n ; }
bool operator()( int n, Foo const& v ) const
{ return n < v.m_nKey ; }
};
// Type traits for string-indexed set
struct string_set_traits: public cds::intrusive::ellen_bintree::traits
{
typedef string_key_extractor key_extractor;
typedef string_less less;
};
// Type traits for int-indexed set
struct int_set_traits: public cds::intrusive::ellen_bintree::traits
{
typedef int_key_extractor key_extractor;
typedef int_less less;
};
// Declare string-indexed set
string_set_type theStringSet;
// Declare int-indexed set
int_set_type theIntSet;
// Now we can use theStringSet and theIntSet in our program
// ...

Member Function Documentation

◆ check_consistency()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
bool cds::intrusive::EllenBinTree< 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.

◆ clear()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
void cds::intrusive::EllenBinTree< 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 leaf the disposer will be called after unlinking.

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

◆ contains() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::contains ( Q const &  key) const
inline

Checks whether the set 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 Q , typename Less >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::contains ( Q const &  key,
Less  pred 
) const
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 and should meet Predicate requirements. Less must imply the same element order as the comparator used for building the set. pred should accept arguments of type Q, key_type, value_type in any combination.

◆ erase() [1/2]

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

Deletes the item from the tree.

The function searches an item with key equal to key in the tree, unlinks it from the tree, and returns true. If the item with key equal to key is not found the function return false.

Note the Traits::less and/or Traits::compare predicate should accept a parameter of type Q that can be not the same as value_type.

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

◆ erase() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Func >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::erase ( Q const &  key,
Func  f 
)
inline

Deletes the item from the tree.

The function searches an item with key equal to key in the tree, call f functor with item found, unlinks it from the tree, and returns true. The disposer specified in Traits class template parameter is called by garbage collector GC asynchronously.

The Func interface is

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

If the item with key equal to key is not found the function return false.

Note the Traits::less and/or Traits::compare predicate should accept a parameter of type Q that can be not the same as value_type.

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

◆ erase_with() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Less >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::erase_with ( const Q &  key,
Less  pred 
)
inline

Delete the item from the tree with comparing functor pred.

The function is an analog of erase(Q const&) but pred predicate is used for key comparing. 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 tree.

◆ erase_with() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Less , typename Func >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::erase_with ( Q const &  key,
Less  pred,
Func  f 
)
inline

Delete the item from the tree with comparing functor pred.

The function is an analog of erase(Q const&, Func) but pred predicate is used for key comparing. 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 tree.

◆ extract()

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

Extracts an item from the tree.

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 the item with the key equal to key is not found the function returns empty exempt_ptr.

RCU synchronize method can be called. RCU should NOT be locked. The function does not call the disposer for the item found. The disposer 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::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::extract_max ( )
inline

Extracts an item with maximal key from the tree.

The function searches an item with maximal key, unlinks it, and returns exempt_ptr pointer to the rightmost item. If the tree is empty the function returns empty exempt_ptr.

Note
Due the concurrent nature of the tree, 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 rightmost 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 call the disposer for the item found. The disposer will be implicitly invoked when the returned object is destroyed or when its release() member function is called.

◆ extract_min()

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

Extracts an item with minimal key from the tree.

The function searches an item with minimal key, unlinks it, and returns exempt_ptr pointer to the leftmost item. If the tree is empty the function returns empty exempt_ptr.

Note
Due the concurrent nature of the tree, 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 call the disposer for the item found. The disposer 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::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::extract_with ( Q const &  key,
Less  pred 
)
inline

Extracts an item from the set 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 tree.

◆ find()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q , typename Func >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::find ( Q &  key,
Func  f 
) const
inline

Finds 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, Q& key );
};

where item is the item found, key is the find function argument.

The functor can change non-key fields of item. Note that the functor is only guarantee that item cannot be disposed during functor is executing. The functor does not serialize simultaneous access to the tree item. If such access is possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.

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 Q , typename Less , typename Func >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::find_with ( Q &  key,
Less  pred,
Func  f 
) const
inline

Finds the key key with comparing functor pred.

The function is an analog of find(Q&, Func) but pred is used for key comparison. Less functor 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 tree.

◆ get()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Q >
value_type* cds::intrusive::EllenBinTree< 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::intrusive::EllenBinTree< 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 value_type and Q in any order. pred must imply the same element order as the comparator used for building the tree.

◆ insert() [1/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::insert ( value_type val)
inline

Inserts new node.

The function inserts val in the tree if it does not contain an item with key equal to val.

The function applies RCU lock internally.

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

◆ insert() [2/2]

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Func >
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::insert ( value_type val,
Func  f 
)
inline

Inserts new node.

This function is intended for derived non-intrusive containers.

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

  • create item with key only
  • insert new item into the tree
  • if inserting is success, calls f functor to initialize value-field of val.

The functor signature is:

void func( value_type& val );

where val is the item inserted. User-defined functor f should guarantee that during changing val no any other changes could be made on this tree's item by concurrent threads. The user-defined functor is called only if the inserting is success.

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::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::size ( ) const
inline

Returns item count in the tree.

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 that.

◆ unlink()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
bool cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::unlink ( value_type val)
inline

Unlinks the item val from the tree.

The function searches the item val in the tree and unlink it from the tree if it is found and is equal to val.

Difference between erase() and unlink() functions: erase() finds a key and deletes the item found. unlink() finds an item by key and deletes it only if val is an item of the tree, i.e. the pointer to item found is equal to &val .

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

The disposer specified in Traits class template parameter is called by garbage collector GC asynchronously.

The function returns true if success and false otherwise.

◆ unsafe_clear()

template<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
void cds::intrusive::EllenBinTree< 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<class RCU , typename Key , typename T , class Traits = ellen_bintree::traits>
template<typename Func >
std::pair<bool, bool> cds::intrusive::EllenBinTree< cds::urcu::gc< RCU >, Key, T, Traits >::update ( value_type val,
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 set, then val is inserted into the set iff bAllowInsert is true. Otherwise, the functor func is called with item found. The functor func signature is:

void func( bool bNew, value_type& item, value_type& val );

with arguments:

  • bNew - true if the item has been inserted, false otherwise
  • item - item of the set
  • val - argument val passed into the update() function If new item has been inserted (i.e. bNew is true) then item and val arguments refer to the same thing.

The functor can change non-key fields of the item; 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:36 by Doxygen 1.8.13