cds  1.4.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits > Class Template Reference

Michael's hash set (template specialization for gc::nogc) More...

#include <cds/intrusive/michael_set_nogc.h>

Public Types

typedef OrderedList bucket_type
 type of ordered list used as a bucket implementation
 
typedef Traits options
 Traits template parameters.
 
typedef bucket_type::value_type value_type
 type of value stored in the list
 
typedef gc::nogc gc
 Garbage collector.
 
typedef bucket_type::key_comparator key_comparator
 key comparision functor
 
typedef bucket_type::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
cds::details::Allocator
< bucket_type, typename
options::allocator > 
bucket_table_allocator
 Bucket table allocator.
 
typedef
michael_set::details::iterator
< bucket_type, false > 
iterator
 Forward iterator. More...
 
typedef
michael_set::details::iterator
< bucket_type, true > 
const_iterator
 Const forward iterator. More...
 

Public Member Functions

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...
 
 MichaelHashSet (size_t nMaxItemCount, size_t nLoadFactor)
 Initializes hash set. More...
 
 ~MichaelHashSet ()
 Clears hash set object and destroys it.
 
bool insert (value_type &val)
 Inserts new node. More...
 
template<typename Func >
std::pair< bool, bool > ensure (value_type &val, Func func)
 Ensures that the item exists in the set. More...
 
template<typename Q >
value_typefind (Q const &val)
 Finds the key val. More...
 
template<typename Q , typename Less >
value_typefind_with (Q const &val, Less pred)
 Finds the key val 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 (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...
 
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.
 
size_t bucket_count () const
 Returns the size of hash table. More...
 
const_iterator begin () const
 Returns a forward const iterator addressing the first element in a set.
 
const_iterator cbegin ()
 
const_iterator end () const
 Returns an const iterator that addresses the location succeeding the last element in a set.
 
const_iterator cend ()
 

Protected Member Functions

template<typename Q >
size_t hash_value (Q const &key) const
 Calculates hash value of key.
 
template<typename Q >
bucket_typebucket (Q const &key)
 Returns the bucket (ordered list) for key.
 

Protected Attributes

item_counter m_ItemCounter
 Item counter.
 
hash m_HashFunctor
 Hash functor.
 
bucket_typem_Buckets
 bucket table
 

Detailed Description

template<class OrderedList, class Traits = michael_set::type_traits>
class cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >

Michael's hash set (template specialization for gc::nogc)

This specialization is intended for so-called persistent usage when no item reclamation may be performed. The class does not support deleting of list item.

See MichaelHashSet for description of template parameters. The template parameter OrderedList should be any gc::nogc-derived ordered list, for example, persistent MichaelList.

The interface of the specialization is a slightly different.

Member Typedef Documentation

template<class OrderedList , class Traits = michael_set::type_traits>
typedef michael_set::details::iterator< bucket_type, true > cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::const_iterator

Const forward iterator.

For iterator's features and requirements see iterator

template<class OrderedList , class Traits = michael_set::type_traits>
typedef michael_set::details::iterator< bucket_type, false > cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::iterator

Forward iterator.

The forward iterator for Michael's set is based on OrderedList forward iterator and has some features:

  • it has no post-increment operator
  • it iterates items in unordered fashion

Constructor & Destructor Documentation

template<class OrderedList , class Traits = michael_set::type_traits>
cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::MichaelHashSet ( size_t  nMaxItemCount,
size_t  nLoadFactor 
)
inline

Initializes hash set.

See MichaelHashSet ctor for explanation

Parameters
nMaxItemCountestimation of max item count in the hash set
nLoadFactorload factor: estimation of max number of items in the bucket

Member Function Documentation

template<class OrderedList , class Traits = michael_set::type_traits>
iterator cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::begin ( )
inline

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

For empty set

begin() == end()
template<class OrderedList , class Traits = michael_set::type_traits>
size_t cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::bucket_count ( ) const
inline

Returns the size of hash table.

Since MichaelHashSet cannot dynamically extend the hash table size, the value returned is an constant depending on object initialization parameters; see MichaelHashSet::MichaelHashSet for explanation.

template<class OrderedList , class Traits = michael_set::type_traits>
void cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::clear ( )
inline

Clears the set (non-atomic)

The function unlink all items from the set. The function is not atomic. It cleans up each bucket and then resets the item counter to zero. If there are a thread that performs insertion while clear is working the result is undefined in general case: empty() may return true but the set may contain item(s). Therefore, clear may be used only for debugging purposes.

For each item the disposer is called after unlinking.

template<class OrderedList , class Traits = michael_set::type_traits>
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::empty ( ) const
inline

Checks if the set is empty.

Emptiness is checked by item counting: if item count is zero then the set is empty. Thus, the correct item counting feature is an important part of Michael's set implementation.

template<class OrderedList , class Traits = michael_set::type_traits>
iterator cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, 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 OrderedList , class Traits = michael_set::type_traits>
template<typename Func >
std::pair<bool, bool> cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::ensure ( value_type 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 item val not found in the set, then val is inserted into the set. Otherwise, the functor func is called with item found. The functor 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 ensure function If new item has been inserted (i.e. bNew is true) then item and val arguments refers 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.

You can pass func argument by value or by reference using boost::ref or cds::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 OrderedList , class Traits = michael_set::type_traits>
template<typename Q >
value_type* cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::find ( Q const &  val)
inline

Finds the key val.

The function searches the item with key equal to val and returns pointer to item found, otherwise NULL.

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 OrderedList , class Traits = michael_set::type_traits>
template<typename Q , typename Func >
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, 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 can pass f argument by value or by reference using boost::ref or cds::ref.

The functor can change non-key fields of item. The functor does not serialize simultaneous access to the set 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 can 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 OrderedList , class Traits = michael_set::type_traits>
template<typename Q , typename Less , typename Func >
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::find ( 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. pred must imply the same element order as the comparator used for building the set.

template<class OrderedList , class Traits = michael_set::type_traits>
template<typename Q , typename Func >
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, 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 can pass f argument by value or by reference using boost::ref or cds::ref.

The functor can change non-key fields of item. The functor does not serialize simultaneous access to the set 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 OrderedList , class Traits = michael_set::type_traits>
template<typename Q , typename Less >
value_type* cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, 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. pred must imply the same element order as the comparator used for building the set.

template<class OrderedList , class Traits = michael_set::type_traits>
template<typename Q , typename Less , typename Func >
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, 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. pred must imply the same element order as the comparator used for building the set.

template<class OrderedList , class Traits = michael_set::type_traits>
bool cds::intrusive::MichaelHashSet< gc::nogc, OrderedList, Traits >::insert ( value_type val)
inline

Inserts new node.

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

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


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:59 by Doxygen 1.8.3.1