|
cds
2.3.3
|
Michael's hash map (template specialization for cds::gc::nogc)
More...
#include <cds/container/michael_map_nogc.h>
Public Types | |
| typedef cds::gc::nogc | gc |
| No garbage collector. | |
| typedef OrderedList | ordered_list |
| type of ordered list used as a bucket implementation | |
| typedef Traits | traits |
| Map traits. | |
| typedef ordered_list::key_type | key_type |
| key type | |
| typedef ordered_list::mapped_type | mapped_type |
| type of value to be stored in the map | |
| typedef ordered_list::value_type | value_type |
| Pair used as the some functor's argument. | |
| typedef ordered_list::key_comparator | key_comparator |
| key comparing functor | |
| typedef cds::opt::v::hash_selector< typename traits::hash >::type | hash |
| Hash functor for key_type and all its derivatives that you use. | |
| typedef traits::item_counter | item_counter |
| Item counter type. | |
| typedef traits::allocator | allocator |
| Bucket table allocator. | |
| typedef ordered_list::stat | stat |
| Internal statistics. | |
Public Member Functions | |
| MichaelHashMap (size_t nMaxItemCount, size_t nLoadFactor) | |
| Initialize the map. More... | |
| ~MichaelHashMap () | |
| Clears hash set and destroys it. | |
| template<typename K > | |
| iterator | insert (const K &key) |
| Inserts new node with key and default value. More... | |
| template<typename K , typename V > | |
| iterator | insert (K const &key, V const &val) |
| Inserts new node. More... | |
| template<typename K , typename Func > | |
| iterator | insert_with (const K &key, Func func) |
| Inserts new node and initialize it by a functor. More... | |
| template<typename K , typename... Args> | |
| iterator | emplace (K &&key, Args &&...args) |
For key key inserts data of type mapped_type created from args. More... | |
| template<typename K > | |
| std::pair< iterator, bool > | update (const K &key, bool bAllowInsert=true) |
| Updates the item. More... | |
| template<typename K > | |
| iterator | contains (K const &key) |
Checks whether the map contains key. More... | |
| template<typename K , typename Less > | |
| iterator | contains (K const &key, Less pred) |
Checks whether the map contains key using pred predicate for searching. More... | |
| void | clear () |
| Clears the map (not atomic) | |
| bool | empty () const |
| Checks whether the map is empty. More... | |
| size_t | size () const |
| Returns item count in the map. 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 iterator_type< false > | iterator |
| Forward iterator. More... | |
| typedef iterator_type< true > | const_iterator |
| Const forward iterator. | |
| 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 map (template specialization for cds::gc::nogc)
This specialization is so-called append-only when no item reclamation may be performed. The class does not support deleting of map item.
See MichaelHashMap for description of template parameters.
| typedef iterator_type< false > cds::container::MichaelHashMap< cds::gc::nogc, OrderedList, Traits >::iterator |
Forward iterator.
The forward iterator for Michael's map is based on OrderedList forward iterator and has some features:
The iterator interface:
|
inline |
Initialize the map.
The Michael's hash map 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)]. Note, that many popular STL hash map implementation uses load factor 1.
The ctor defines hash table size as rounding nMacItemCount / 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 MichaelHashMap cannot dynamically extend the hash table size, the value returned is an constant depending on object initialization parameters; see MichaelHashMap::MichaelHashMap for explanation.
|
inline |
Checks whether the map contains key.
The function searches the item with key equal to key and returns an iterator pointed to item found and end() otherwise
|
inline |
Checks whether the map 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. pred must imply the same element order as the comparator used for building the map. Hash functor specified in Traits should accept parameters of type K.
|
inline |
For key key inserts data of type mapped_type created from args.
key_type should be constructible from type K
Returns an iterator pointed to inserted value, or end() if inserting is failed
|
inline |
Checks whether the map is empty.
atomicity::empty_item_counter in traits::item_counter, the function always returns true.
|
inline |
|
inline |
Inserts new node with key and default value.
The function creates a node with key and default value, and then inserts the node created into the map.
Preconditions:
K. In trivial case, K is equal to key_type.Returns an iterator pointed to inserted value, or end() if inserting is failed
|
inline |
Inserts new node.
The function creates a node with copy of val value and then inserts the node created into the map.
Preconditions:
key of type K.val of type V.Returns an iterator pointed to inserted value, or end() if inserting is failed
|
inline |
Inserts new node and initialize it by a functor.
This function inserts new node with key key and if inserting is successful then it calls func functor with signature
The argument item of user-defined functor func is the reference to the map's item inserted. item.second is a reference to item's value that may be changed.
The user-defined functor it is called only if the inserting is successful. The key_type should be constructible from value of type K.
The function allows to split creating of new item into two part:
key;f functorThis can be useful if complete initialization of object of mapped_type is heavyweight and it is preferable that the initialization should be completed only if inserting is successful.
Returns an iterator pointed to inserted value, or end() if inserting is failed
|
inline |
Returns item count in the map.
If you use atomicity::empty_item_counter in traits::item_counter, the function always returns 0.
|
inline |
Updates the item.
If key is not in the map and bAllowInsert is true, the function inserts a new item. Otherwise, the function returns an iterator pointing to the item found.
Returns std::pair<iterator, bool> where first is an iterator pointing to item found or inserted (if inserting is not allowed and key is not found, the iterator will be end()),
second is true if new item has been added or false if the item already is in the map.