cds
2.3.2
|
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. More... | |
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. | |
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.
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
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:
The iterator interface:
|
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.
nMaxItemCount | estimation of max item count in the hash set |
nLoadFactor | load factor: estimation of max number of items in the bucket |
|
inline |
|
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.
|
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
.
|
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.
|
inline |
Inserts data of type value_type constructed with std::forward<Args>(args)...
Return an iterator pointing to inserted item if success end() otherwise
|
inline |
Checks if the set is empty.
atomicity::empty_item_counter
in traits::item_counter
, the function always returns true
.
|
inline |
|
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()
|
inline |
Returns item count in the set.
atomicity::empty_item_counter
in traits::item_counter
, the function always returns 0.
|
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.