cds  1.4.0
Data Structures | Public Types | Public Member Functions
cds::container::SplitListSet< GC, T, Traits > Class Template Reference

Split-ordered list set. More...

#include <cds/container/split_list_set.h>

Inheritance diagram for cds::container::SplitListSet< GC, T, Traits >:
cds::intrusive::SplitListSet< GC, Traits::ordered_list, Traits >

Data Structures

class  iterator_type
 Forward iterator. More...
 

Public Types

typedef options::gc gc
 Garbage collector.
 
typedef options::value_type value_type
 type of value stored in the list
 
typedef options::ordered_list ordered_list
 Underlying ordered list class.
 
typedef base_class::key_comparator key_comparator
 key compare functor
 
typedef base_class::hash hash
 Hash functor for value_type and all its derivatives that you use.
 
typedef base_class::item_counter item_counter
 Item counter type.
 
typedef iterator_type< false > iterator
 Forward iterator.
 
typedef iterator_type< true > const_iterator
 Const forward iterator.
 

Public Member Functions

 SplitListSet ()
 Initializes split-ordered list of default capacity. More...
 
 SplitListSet (size_t nItemCount, size_t nLoadFactor=1)
 Initializes split-ordered list. More...
 
iterator begin ()
 Returns a forward iterator addressing the first element in a set. More...
 
iterator end ()
 Returns an iterator that addresses the location succeeding the last element in a set. More...
 
const_iterator begin () const
 Returns a forward const iterator addressing the first element in a set.
 
const_iterator end () const
 Returns an const iterator that addresses the location succeeding the last element in a set.
 
template<typename Q >
bool insert (Q const &val)
 Inserts new node. More...
 
template<typename Q , typename Func >
bool insert (Q const &val, Func f)
 Inserts new node. More...
 
template<typename... Args>
bool emplace (Args &&...args)
 Inserts data of type value_type constructed with std::forward<Args>(args)... More...
 
template<typename Q , typename Func >
std::pair< bool, bool > ensure (Q const &val, Func func)
 Ensures that the item exists in the set. More...
 
template<typename Q >
bool erase (Q const &key)
 Deletes key from the set. More...
 
template<typename Q , typename Less >
bool erase_with (Q const &key, Less pred)
 Deletes the item from the set using pred predicate for searching. More...
 
template<typename Q , typename Func >
bool erase (Q const &key, Func f)
 Deletes key from the set. More...
 
template<typename Q , typename Less , typename Func >
bool erase_with (Q const &key, Less pred, Func f)
 Deletes the item from the set using pred predicate for searching. More...
 
template<typename Q , typename Func >
bool find (Q &val, Func f)
 Finds the key val. More...
 
template<typename Q , typename Less , typename Func >
bool find_with (Q &val, Less pred, Func f)
 Finds the key val using pred predicate for searching. More...
 
template<typename Q , typename Func >
bool find (Q const &val, Func f)
 Finds the key val. More...
 
template<typename Q , typename Less , typename Func >
bool find_with (Q const &val, Less pred, Func f)
 Finds the key val using pred predicate for searching. More...
 
template<typename Q >
bool find (Q const &val)
 Finds the key val. More...
 
template<typename Q , typename Less >
bool find_with (Q const &val, Less pred)
 Finds the key val using pred predicate for searching. More...
 
void clear ()
 Clears the set (non-atomic) More...
 
bool empty () const
 Checks if the set is empty. More...
 
size_t size () const
 Returns item count in the set.
 

Additional Inherited Members

- Protected Types inherited from cds::intrusive::SplitListSet< GC, Traits::ordered_list, Traits >
typedef Traits options
 Traits template parameters.
 
typedef GC gc
 Garbage collector.
 
typedef Traits::ordered_list ordered_list
 type of ordered list used as base for split-list
 
typedef ordered_list::value_type value_type
 type of value stored in the split-list
 
typedef
ordered_list::key_comparator 
key_comparator
 key comparision functor
 
typedef ordered_list::disposer disposer
 Node disposer functor.
 
typedef
cds::opt::v::hash_selector
< typename options::hash >
::type 
hash
 Hash functor for value_type and all its derivatives that you use.
 
typedef options::item_counter item_counter
 Item counter type.
 
typedef options::back_off back_off
 back-off strategy for spinning
 
typedef options::memory_model memory_model
 Memory ordering. See cds::opt::memory_model option.
 
typedef iterator_type< false > iterator
 Forward iterator. More...
 
typedef iterator_type< true > const_iterator
 Const forward iterator. More...
 
typedef ordered_list::node_type list_node_type
 Node type as declared in ordered list.
 
typedef split_list::node
< list_node_type
node_type
 split-list node type
 
typedef node_type dummy_node_type
 dummy node type
 
typedef
split_list::node_traits
< typename
ordered_list::node_traits > 
node_traits
 Split-list node traits. More...
 
- Protected Member Functions inherited from cds::intrusive::SplitListSet< GC, Traits::ordered_list, Traits >
 SplitListSet ()
 Initialize split-ordered list of default capacity. More...
 
 SplitListSet (size_t nItemCount, size_t nLoadFactor=1)
 Initialize split-ordered list. More...
 
bool insert (value_type &val)
 Inserts new node. More...
 
bool insert (value_type &val, Func f)
 Inserts new node. More...
 
std::pair< bool, bool > ensure (value_type &val, Func func)
 Ensures that the val exists in the set. More...
 
bool unlink (value_type &val)
 Unlinks the item val from the set. More...
 
bool erase (Q const &val)
 Deletes the item from the set. More...
 
bool erase (Q const &val, Func f)
 Deletes the item from the set. More...
 
bool erase_with (const Q &val, Less pred)
 Deletes the item from the set with comparing functor pred. More...
 
bool erase_with (Q const &val, Less pred, Func f)
 Deletes the item from the set with comparing functor pred. More...
 
bool find (Q &val, Func f)
 Finds the key val. More...
 
bool find (Q const &val, Func f)
 Finds the key val. More...
 
bool find (Q const &val)
 Finds the key val. More...
 
bool find_with (Q &val, Less pred, Func f)
 Finds the key val with pred predicate for comparing. More...
 
bool find_with (Q const &val, Less pred, Func f)
 Finds the key val with pred predicate for comparing. More...
 
bool find_with (Q const &val, Less pred)
 Finds the key val with pred predicate for comparing. More...
 
size_t size () const
 Returns item count in the set.
 
bool empty () const
 Checks if the set is empty. More...
 
void clear ()
 Clears the set (non-atomic) More...
 
iterator begin ()
 Returns a forward iterator addressing the first element in a split-list. More...
 
const_iterator begin () const
 Returns a forward const iterator addressing the first element in a split-list.
 
iterator end ()
 Returns an iterator that addresses the location succeeding the last element in a split-list. More...
 
const_iterator end () const
 Returns an const iterator that addresses the location succeeding the last element in a split-list.
 

Detailed Description

template<class GC, class T, class Traits = split_list::type_traits>
class cds::container::SplitListSet< GC, T, Traits >

Split-ordered list set.

Hash table implementation based on split-ordered list algorithm discovered by Ori Shalev and Nir Shavit, see

See intrusive::SplitListSet for a brief description of the split-list algorithm.

Template parameters:

There are the specializations:

Usage

You should decide what garbage collector you want, and what ordered list you want to use. Split-ordered list is original data structure based on an ordered list. Suppose, you want construct split-list set based on gc::PTB GC and LazyList as ordered list implementation. So, you beginning your program with following include:

#include <cds/container/lazy_list_ptb.h>
#include <cds/container/split_list_set.h>
namespace cc = cds::container ;
// The data belonged to split-ordered list
sturuct foo {
int nKey; // key field
std::string strValue ; // value field
};

The inclusion order is important: first, include header for ordered-list implementation (for this example, cds/container/lazy_list_ptb.h), then the header for split-list set cds/container/split_list_set.h.

Now, you should declare traits for split-list set. The main parts of traits are a hash functor for the set and a comparing functor for ordered list. Note that we define several function in foo_hash and foo_less functors for different argument types since we want call our SplitListSet object by the key of type int and by the value of type foo.

The second attention: instead of using LazyList in SplitListSet traits we use a tag cds::contaner::lazy_list_tag for the lazy list. The split-list requires significant support from underlying ordered list class and it is not good idea to dive you into deep implementation details of split-list and ordered list interrelations. The tag paradigm simplifies split-list interface.

// foo hash functor
struct foo_hash {
size_t operator()( int key ) const { return std::hash( key ) ; }
size_t operator()( foo const& item ) const { return std::hash( item.nKey ) ; }
};
// foo comparator
struct foo_less {
bool operator()(int i, foo const& f ) const { return i < f.nKey ; }
bool operator()(foo const& f, int i ) const { return f.nKey < i ; }
bool operator()(foo const& f1, foo const& f2) const { return f1.nKey < f2.nKey; }
};
// SplitListSet traits
struct foo_set_traits: public cc::split_list::type_traits
{
typedef cc::lazy_list_tag ordered_list ; // what type of ordered list we want to use
typedef foo_hash hash ; // hash functor for our data stored in split-list set
// Type traits for our LazyList class
struct ordered_list_traits: public cc::lazy_list::type_traits
{
typedef foo_less less ; // use our foo_less as comparator to order list nodes
} ;
};

Now you are ready to declare our set class based on SplitListSet:

typedef cc::SplitListSet< cds::gc::PTB, foo, foo_set_traits > foo_set ;

You may use the modern option-based declaration instead of classic type-traits-based one:

typedef cc:SplitListSet<
cs::gc::PTB // GC used
,foo // type of data stored
,cc::split_list::make_traits< // metafunction to build split-list traits
cc::split_list::ordered_list<cc::lazy_list_tag> // tag for underlying ordered list implementation
,cc::opt::hash< foo_hash > // hash functor
,cc::split_list::ordered_list_traits< // ordered list traits desired
cc::lazy_list::make_traits< // metafunction to build lazy list traits
cc::opt::less< foo_less > // less-based compare functor
>::type
>
>::type
> foo_set ;

In case of option-based declaration using split_list::make_traits metafunction the struct foo_set_traits is not required.

Now, the set of type foo_set is ready to use in your program.

Note that in this example we show only mandatory type_traits parts, optional ones is the default and they are inherited from cds::container::split_list::type_traits. The cds library contains many other options for deep tuning of behavior of the split-list and ordered-list containers.

Constructor & Destructor Documentation

template<class GC, class T, class Traits = split_list::type_traits>
cds::container::SplitListSet< GC, T, Traits >::SplitListSet ( )
inline

Initializes split-ordered list of default capacity.

The default capacity is defined in bucket table constructor. See intrusive::split_list::expandable_bucket_table, intrusive::split_list::static_bucket_table which selects by intrusive::split_list::dynamic_bucket_table option.

template<class GC, class T, class Traits = split_list::type_traits>
cds::container::SplitListSet< GC, T, Traits >::SplitListSet ( size_t  nItemCount,
size_t  nLoadFactor = 1 
)
inline

Initializes split-ordered list.

Parameters
nItemCountestimate average of item count
nLoadFactorload factor - average item count per bucket. Small integer up to 8, default is 1.

Member Function Documentation

template<class GC, class T, class Traits = split_list::type_traits>
iterator cds::container::SplitListSet< GC, T, Traits >::begin ( )
inline

Returns a forward iterator addressing the first element in a set.

For empty set

begin() == end()
template<class GC, class T, class Traits = split_list::type_traits>
void cds::container::SplitListSet< GC, T, Traits >::clear ( )
inline

Clears the set (non-atomic)

The function unlink all items from the set. The function is not atomic and not lock-free and should be used for debugging only.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename... Args>
bool cds::container::SplitListSet< GC, T, Traits >::emplace ( Args &&...  args)
inline

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

Returns true if inserting successful, false otherwise.

Note
This function is available only for compiler that supports variadic template and move semantics
template<class GC, class T, class Traits = split_list::type_traits>
bool cds::container::SplitListSet< GC, T, Traits >::empty ( ) const
inline

Checks if the set is empty.

Emptiness is checked by item counting: if item count is zero then assume that the set is empty. Thus, the correct item counting feature is an important part of split-list set implementation.

template<class GC, class T, class Traits = split_list::type_traits>
iterator cds::container::SplitListSet< GC, T, Traits >::end ( )
inline

Returns an iterator that addresses the location succeeding the last element in a set.

Do not use the value returned by end function to access any item. The returned value can be used only to control reaching the end of the set. For empty set

begin() == end()
template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Func >
std::pair<bool, bool> cds::container::SplitListSet< GC, T, Traits >::ensure ( Q const &  val,
Func  func 
)
inline

Ensures that the item exists in the set.

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

If the val key not found in the set, then the new item created from val is inserted into the set. Otherwise, the functor func is called with the item found. The functor Func should be a function with signature:

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

or a functor:

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

with arguments:

  • bNew - true if the item has been inserted, false otherwise
  • item - item of the set
  • val - argument val passed into the ensure function

The functor may 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.

You may pass func argument by reference using boost::ref.

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

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q >
bool cds::container::SplitListSet< GC, T, Traits >::erase ( Q const &  key)
inline

Deletes key from the set.

The item comparator should be able to compare the values of type value_type and the type Q.

Return true if key is found and deleted, false otherwise

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::erase ( Q const &  key,
Func  f 
)
inline

Deletes key from the set.

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 const& val) ;
};

The functor may be passed by reference using boost:ref

Since the key of SplitListSet's value_type is not explicitly specified, template parameter Q defines the key type searching in the list. The list item comparator should be able to compare the values of the type value_type and the type Q.

Return true if key is found and deleted, false otherwise

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Less >
bool cds::container::SplitListSet< GC, T, Traits >::erase_with ( Q const &  key,
Less  pred 
)
inline

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

The function is an analog of erase(Q 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 set.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Less , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::erase_with ( Q const &  key,
Less  pred,
Func  f 
)
inline

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

The function is an analog of erase(Q 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 set.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::find ( Q &  val,
Func  f 
)
inline

Finds the key val.

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

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

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

You may pass f argument by reference using boost::ref or cds::ref.

The functor may 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 set's item. If such access is possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.

The val argument is non-const since it can be used as f functor destination i.e., the functor may modify both arguments.

Note the hash functor specified for class Traits template parameter should accept a parameter of type Q that can be not the same as value_type.

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

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::find ( Q const &  val,
Func  f 
)
inline

Finds the key val.

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

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

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

You may pass f argument by reference using boost::ref or cds::ref.

The functor may 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 set's item. If such access is possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.

Note the hash functor specified for class Traits template parameter should accept a parameter of type Q that can be not the same as value_type.

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

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q >
bool cds::container::SplitListSet< GC, T, Traits >::find ( Q const &  val)
inline

Finds the key val.

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

Note the hash functor specified for class Traits template parameter should accept a parameter of type Q that can be not the same as value_type.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Less , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::find_with ( Q &  val,
Less  pred,
Func  f 
)
inline

Finds the key val using pred predicate for searching.

The function is an analog of find(Q&, 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 set.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Less , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::find_with ( Q const &  val,
Less  pred,
Func  f 
)
inline

Finds the key val using pred predicate for searching.

The function is an analog of find(Q 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 set.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Less >
bool cds::container::SplitListSet< GC, T, Traits >::find_with ( Q const &  val,
Less  pred 
)
inline

Finds the key val using pred predicate for searching.

The function is an analog of find(Q 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 set.

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q >
bool cds::container::SplitListSet< GC, T, Traits >::insert ( Q const &  val)
inline

Inserts new node.

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

The type Q should contain as minimum the complete key for the node. The object of value_type should be constructible from a value of type Q. In trivial case, Q is equal to value_type.

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

template<class GC, class T, class Traits = split_list::type_traits>
template<typename Q , typename Func >
bool cds::container::SplitListSet< GC, T, Traits >::insert ( Q const &  val,
Func  f 
)
inline

Inserts new node.

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

  • create item with key only
  • insert new item into the set
  • 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 set's item by concurrent threads. The user-defined functor is called only if the inserting is success. It may be passed by reference using boost::ref


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

cds 1.4.0 Developed by Maxim Khiszinsky aka khizmax 2007 - 2012
Autogenerated Mon May 20 2013 00:37:57 by Doxygen 1.8.3.1