cds  2.2.0
cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits > Class Template Reference

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

#include <cds/container/michael_set_nogc.h>

Public Types

typedef cds::gc::nogc gc
 Garbage collector.
 
typedef OrderedList ordered_list
 type of ordered list to be used as a bucket implementation
 
typedef Traits traits
 Set traits.
 
typedef ordered_list::value_type value_type
 type of value stored in the list
 
typedef ordered_list::key_comparator key_comparator
 key comparison functor
 
typedef ordered_list::stat stat
 Internal statistics.
 
typedef cds::opt::v::hash_selector< typename traits::hash >::type hash
 Hash functor for value_type and all its derivatives that you use.
 
typedef traits::item_counter item_counter
 Item counter type.
 
typedef traits::allocator allocator
 Bucket table allocator.
 

Public Member Functions

 MichaelHashSet (size_t nMaxItemCount, size_t nLoadFactor)
 Initialize hash set. More...
 
 ~MichaelHashSet ()
 Clears hash set and destroys it.
 
template<typename Q >
iterator insert (const Q &val)
 Inserts new node. More...
 
template<typename... Args>
iterator emplace (Args &&... args)
 Inserts data of type value_type constructed with std::forward<Args>(args)... More...
 
template<typename Q >
std::pair< iterator, bool > update (Q const &val, bool bAllowInsert=true)
 Updates the element. More...
 
template<typename Q >
iterator contains (Q const &key)
 Checks whether the set contains key. More...
 
template<typename Q , typename Less >
iterator contains (Q const &key, Less pred)
 Checks whether the set contains key using pred predicate for searching. More...
 
void clear ()
 Clears the set (not atomic)
 
bool empty () const
 Checks if the set is empty. More...
 
size_t size () const
 Returns item count in the set.
 
stat const & statistics () const
 Returns const reference to internal statistics.
 
size_t bucket_count () const
 Returns the size of hash table. More...
 

Forward iterators

typedef michael_set::details::iterator< internal_bucket_type, false > iterator
 Forward iterator. More...
 
typedef michael_set::details::iterator< internal_bucket_type, true > const_iterator
 Const forward iterator. 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 cbegin () 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.
 
const_iterator cend () const
 Returns an const iterator that addresses the location succeeding the last element in a set.
 

Detailed Description

template<class OrderedList, class Traits = michael_set::traits>
class cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >

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

This specialization is so-called append-only 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, append-only MichaelList.

Member Typedef Documentation

§ const_iterator

template<class OrderedList , class Traits = michael_set::traits>
typedef michael_set::details::iterator< internal_bucket_type, true > cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::const_iterator

Const forward iterator.

For iterator's features and requirements see iterator

§ iterator

template<class OrderedList , class Traits = michael_set::traits>
typedef michael_set::details::iterator< internal_bucket_type, false > cds::container::MichaelHashSet< cds::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

The iterator interface:

class iterator {
public:
// Default constructor
// Copy construtor
iterator( iterator const& src );
// Dereference operator
value_type * operator ->() const;
// Dereference operator
value_type& operator *() const;
// Preincrement operator
iterator& operator ++();
// Assignment operator
iterator& operator = (iterator const& src);
// Equality operators
bool operator ==(iterator const& i ) const;
bool operator !=(iterator const& i ) const;
};

Constructor & Destructor Documentation

§ MichaelHashSet()

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

Initialize hash set.

The Michael's hash set is non-expandable container. You should point the average count of items nMaxItemCount when you create an object. nLoadFactor parameter defines average count of items per bucket and it should be small number between 1 and 10. Remember, since the bucket implementation is an ordered list, searching in the bucket is linear [O(nLoadFactor)].

The ctor defines hash table size as rounding nMaxItemCount / nLoadFactor up to nearest power of two.

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

Member Function Documentation

§ begin()

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

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

For empty set

begin() == end()

§ bucket_count()

template<class OrderedList , class Traits = michael_set::traits>
size_t cds::container::MichaelHashSet< cds::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.

§ contains() [1/2]

template<class OrderedList , class Traits = michael_set::traits>
template<typename Q >
iterator cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::contains ( Q const &  key)
inline

Checks whether the set contains key.

The function searches the item with key equal to key and returns an iterator pointed to item found if the key is found, or end() 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.

§ contains() [2/2]

template<class OrderedList , class Traits = michael_set::traits>
template<typename Q , typename Less >
iterator cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::contains ( Q const &  key,
Less  pred 
)
inline

Checks whether the set contains key using pred predicate for searching.

The function is an analog of 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.

§ emplace()

template<class OrderedList , class Traits = michael_set::traits>
template<typename... Args>
iterator cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::emplace ( Args &&...  args)
inline

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

Return an iterator pointing to inserted item if success end() otherwise

§ empty()

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

Checks if the set is empty.

The emptiness is checked by the 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.

§ end()

template<class OrderedList , class Traits = michael_set::traits>
iterator cds::container::MichaelHashSet< cds::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()

§ insert()

template<class OrderedList , class Traits = michael_set::traits>
template<typename Q >
iterator cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::insert ( const Q &  val)
inline

Inserts new node.

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

Return an iterator pointing to inserted item if success, otherwise end()

§ update()

template<class OrderedList , class Traits = michael_set::traits>
template<typename Q >
std::pair<iterator, bool> cds::container::MichaelHashSet< cds::gc::nogc, OrderedList, Traits >::update ( Q const &  val,
bool  bAllowInsert = true 
)
inline

Updates the element.

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

If the item val not found in the set, then val is inserted iff bAllowInsert is true.

Returns std::pair<iterator, bool> where first is an iterator pointing to item found or inserted, or end() if bAllowInsert is false,

second is true if new item has been added or false if the item is already in the set.

Warning
For MichaelList as the bucket see insert item troubleshooting. LazyList provides exclusive access to inserted item and does not require any node-level synchronization.

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:38 by Doxygen 1.8.12