|
cds
2.3.3
|
Lock-free skip-list map (template specialization for gc::nogc) More...
#include <cds/container/skip_list_map_nogc.h>
Public Types | |
| typedef cds::gc::nogc | gc |
| Garbage collector. | |
| typedef Key | key_type |
| Key type. | |
| typedef T | mapped_type |
| Mapped type. | |
| typedef std::pair< key_type const, mapped_type > | value_type |
| Key-value pair stored in the map. | |
| typedef Traits | traits |
| Options specified. | |
| typedef base_class::back_off | back_off |
| Back-off strategy. | |
| typedef base_class::allocator_type | allocator_type |
| Allocator type used for allocate/deallocate the skip-list nodes. | |
| typedef base_class::item_counter | item_counter |
| Item counting policy. | |
| typedef base_class::key_comparator | key_comparator |
| key compare functor | |
| typedef base_class::memory_model | memory_model |
Memory ordering, see cds::opt::memory_model option. | |
| typedef base_class::stat | stat |
| internal statistics type | |
| typedef base_class::random_level_generator | random_level_generator |
| random level generator | |
Public Member Functions | |
| SkipListMap () | |
| Default constructor. | |
| ~SkipListMap () | |
| Destructor clears the map. | |
| template<typename K > | |
| iterator | insert (K const &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 (K const &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 in-place from args. More... | |
| template<typename K > | |
| std::pair< iterator, bool > | update (K const &key, bool bInsert=true) |
UPdates data by key. 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) const |
Checks whether the map contains key using pred predicate for searching. More... | |
| value_type * | get_min () const |
| Gets minimum key from the map. More... | |
| value_type * | get_max () const |
| Gets maximum key from the map. More... | |
| void | clear () |
| Clears the map (not atomic) More... | |
| bool | empty () const |
| Checks if the map is empty. More... | |
| size_t | size () const |
| Returns item count in the map. | |
| stat const & | statistics () const |
| Returns const reference to internal statistics. | |
Static Public Member Functions | |
| static constexpr unsigned int | max_height () noexcept |
| Returns maximum height of skip-list. The max height is a constant for each object and does not exceed 32. | |
Forward ordered iterators | |
| typedef base_class::iterator | iterator |
| Forward iterator. More... | |
| typedef base_class::const_iterator | const_iterator |
| Const forward iterator. | |
| iterator | begin () |
| Returns a forward iterator addressing the first element in a map. More... | |
| iterator | end () |
| Returns an iterator that addresses the location succeeding the last element in a map. More... | |
| const_iterator | begin () const |
| Returns a forward const iterator addressing the first element in a map. | |
| const_iterator | cbegin () const |
| Returns a forward const iterator addressing the first element in a map. | |
| const_iterator | end () const |
| Returns an const iterator that addresses the location succeeding the last element in a map. | |
| const_iterator | cend () const |
| Returns an const iterator that addresses the location succeeding the last element in a map. | |
Additional Inherited Members | |
Protected Types inherited from cds::container::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| typedef cds::gc::nogc | gc |
| Garbage collector used. | |
| typedef std::pair< Key const, T > | value_type |
| typedef Traits | traits |
| Options specified. | |
| typedef base_class::back_off | back_off |
| Back-off strategy. | |
| typedef traits::allocator | allocator_type |
| Allocator type used for allocate/deallocate the skip-list nodes. | |
| typedef base_class::item_counter | item_counter |
| Item counting policy used. | |
| typedef maker::key_comparator | key_comparator |
| key comparison functor | |
| typedef base_class::memory_model | memory_model |
| Memory ordering. See cds::opt::memory_model option. | |
| typedef traits::random_level_generator | random_level_generator |
| random level generator | |
| typedef traits::stat | stat |
| internal statistics type | |
| typedef gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set< node_type, value_type > > | guarded_ptr |
| Guarded pointer. | |
| typedef skip_list::details::iterator< typename base_class::iterator > | iterator |
| Iterator type. More... | |
| typedef skip_list::details::iterator< typename base_class::const_iterator > | const_iterator |
| Const iterator type. | |
Protected Types inherited from cds::intrusive::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| typedef node_type::atomic_marked_ptr | atomic_node_ptr |
| Atomic marked node pointer. | |
| typedef node_type::marked_ptr | marked_node_ptr |
| Node marked pointer. | |
| typedef cds::gc::nogc | gc |
| Garbage collector. | |
| typedef std::pair< Key const, T > | value_type |
| type of value stored in the skip-list | |
| typedef Traits | traits |
| Traits template parameter. | |
| typedef traits::hook | hook |
| hook type | |
| typedef hook::node_type | node_type |
| node type | |
| typedef implementation_defined | key_comparator |
| key comparison functor based on opt::compare and opt::less option setter. | |
| typedef traits::disposer | disposer |
| item disposer | |
| typedef get_node_traits< value_type, node_type, hook >::type | node_traits |
| node traits | |
| typedef traits::item_counter | item_counter |
| Item counting policy. | |
| typedef traits::memory_model | memory_model |
Memory ordering, see cds::opt::memory_model option. | |
| typedef traits::random_level_generator | random_level_generator |
| random level generator | |
| typedef traits::allocator | allocator_type |
| allocator for maintaining array of next pointers of the node | |
| typedef traits::back_off | back_off |
| Back-off strategy. | |
| typedef traits::stat | stat |
| internal statistics type | |
| typedef gc::template guarded_ptr< value_type > | guarded_ptr |
| Guarded pointer. | |
| typedef skip_list::details::iterator< gc, node_traits, back_off, false > | iterator |
| Iterator type. More... | |
| typedef skip_list::details::iterator< gc, node_traits, back_off, true > | const_iterator |
| Const iterator type. | |
Protected Member Functions inherited from cds::container::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| SkipListSet () | |
| Default ctor. | |
| ~SkipListSet () | |
| Destructor destroys the set object. | |
| bool | insert (Q const &val) |
| Inserts new node. More... | |
| bool | insert (Q const &val, Func f) |
| Inserts new node. More... | |
| std::pair< bool, bool > | update (const Q &val, Func func, bool bInsert=true) |
| Updates the item. More... | |
| bool | emplace (Args &&...args) |
Inserts data of type value_type created in-place from std::forward<Args>(args)... More... | |
| bool | erase (Q const &key) |
Delete key from the set. More... | |
| bool | erase (Q const &key, Func f) |
Delete key from the set. More... | |
| bool | erase_with (Q const &key, Less pred) |
Deletes the item from the set using pred predicate for searching. More... | |
| bool | erase_with (Q const &key, Less pred, Func f) |
Deletes the item from the set using pred predicate for searching. More... | |
| guarded_ptr | extract (Q const &key) |
Extracts the item from the set with specified key. More... | |
| guarded_ptr | extract_with (Q const &key, Less pred) |
Extracts the item from the set with comparing functor pred. More... | |
| guarded_ptr | extract_min () |
| Extracts an item with minimal key from the set. More... | |
| guarded_ptr | extract_max () |
| Extracts an item with maximal key from the set. More... | |
| bool | find (Q &key, Func f) |
Find the key. More... | |
| bool | find_with (Q &key, Less pred, Func f) |
Finds key using pred predicate for searching. More... | |
| bool | contains (Q const &key) |
Checks whether the set contains key. More... | |
| bool | contains (Q const &key, Less pred) |
Checks whether the set contains key using pred predicate for searching. More... | |
| guarded_ptr | get (Q const &key) |
Finds key and return the item found. More... | |
| guarded_ptr | get_with (Q const &key, Less pred) |
Finds key and return the item found. More... | |
| void | clear () |
| Clears the set (not atomic). More... | |
| bool | empty () const |
| Checks if the set is empty. | |
| size_t | size () const |
| Returns item count in the set. More... | |
| stat const & | statistics () const |
| Returns const reference to internal statistics. | |
| iterator | begin () |
| Returns a forward iterator addressing the first element in a set. | |
| 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. | |
| iterator | end () |
| Returns a forward iterator that addresses the location succeeding the last element in a set. | |
| const_iterator | end () const |
| Returns a forward const iterator that addresses the location succeeding the last element in a set. | |
| const_iterator | cend () const |
| Returns a forward const iterator that addresses the location succeeding the last element in a set. | |
Protected Member Functions inherited from cds::intrusive::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| SkipListSet () | |
| Default constructor. More... | |
| ~SkipListSet () | |
| Clears and destructs the skip-list. | |
| bool | insert (value_type &val) |
| Inserts new node. More... | |
| bool | insert (value_type &val, Func f) |
| Inserts new node. More... | |
| std::pair< bool, bool > | update (value_type &val, Func func, bool bInsert=true) |
| Updates the node. More... | |
| bool | unlink (value_type &val) |
Unlinks the item val from the set. More... | |
| guarded_ptr | extract (Q const &key) |
Extracts the item from the set with specified key. More... | |
| guarded_ptr | extract_with (Q const &key, Less pred) |
Extracts the item from the set with comparing functor pred. More... | |
| guarded_ptr | extract_min () |
| Extracts an item with minimal key from the list. More... | |
| guarded_ptr | extract_max () |
| Extracts an item with maximal key from the list. More... | |
| bool | erase (Q const &key) |
| Deletes the item from the set. More... | |
| bool | erase (Q const &key, Func f) |
| Deletes the item from the set. More... | |
| bool | erase_with (Q const &key, Less pred) |
Deletes the item from the set with comparing functor pred. More... | |
| bool | erase_with (Q const &key, Less pred, Func f) |
Deletes the item from the set with comparing functor pred. More... | |
| bool | find (Q &key, Func f) |
Finds key. More... | |
| bool | find_with (Q &key, Less pred, Func f) |
Finds the key key with pred predicate for comparing. More... | |
| bool | contains (Q const &key) |
Checks whether the set contains key. More... | |
| bool | contains (Q const &key, Less pred) |
Checks whether the set contains key using pred predicate for searching. More... | |
| guarded_ptr | get (Q const &key) |
Finds key and return the item found. More... | |
| guarded_ptr | get_with (Q const &key, Less pred) |
Finds key and return the item found. More... | |
| size_t | size () const |
| Returns item count in the set. More... | |
| bool | empty () const |
| Checks if the set is empty. | |
| void | clear () |
| Clears the set (not atomic) More... | |
| stat const & | statistics () const |
| Returns const reference to internal statistics. | |
| iterator | begin () |
| Returns a forward iterator addressing the first element in a set. | |
| 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. | |
| iterator | end () |
| Returns a forward iterator that addresses the location succeeding the last element in a set. | |
| const_iterator | end () const |
| Returns a forward const iterator that addresses the location succeeding the last element in a set. | |
| const_iterator | cend () const |
| Returns a forward const iterator that addresses the location succeeding the last element in a set. | |
Static Protected Member Functions inherited from cds::intrusive::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| static constexpr unsigned int | max_height () noexcept |
| Returns maximum height of skip-list. The max height is a constant for each object and does not exceed 32. | |
Static Protected Attributes inherited from cds::container::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| static size_t const | c_nHazardPtrCount |
| Count of hazard pointer required for the skip-list. | |
Static Protected Attributes inherited from cds::intrusive::SkipListSet< cds::gc::nogc, std::pair< Key const, T >, Traits > | |
| static unsigned int const | c_nMaxHeight |
Max node height. The actual node height should be in range [0 .. c_nMaxHeight) More... | |
| static size_t const | c_nHazardPtrCount |
| Count of hazard pointer required for the skip-list. | |
Lock-free skip-list map (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 map item. See SkipListMap for detailed description.
Template arguments:
K - type of a key to be stored in the map.T - type of a value to be stored in the map.Traits - map traits, default is skip_list::traits It is possible to declare option-based list with cds::container::skip_list::make_traits metafunction istead of Traits template argument. | typedef base_class::iterator cds::container::SkipListMap< cds::gc::nogc, Key, T, Traits >::iterator |
Forward iterator.
The forward iterator for a split-list has some features:
OrderedList
|
inline |
|
inline |
Clears the map (not atomic)
Finding and/or inserting is prohibited while clearing. Otherwise an unpredictable result may be encountered. Thus, clear() may be used only for debugging purposes.
|
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 if the key is found, and end() otherwise
|
inline |
Checks whether the map contains key using pred predicate for searching.
The function is similar to 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 map.
|
inline |
For key key inserts data of type mapped_type created in-place from args.
key_type should be constructible from type K
Returns true if inserting successful, false otherwise.
|
inline |
Checks if the map is empty.
Emptiness is checked by item counting: if item count is zero then the map is empty. Thus, the correct item counting feature is an important part of Michael's map implementation.
|
inline |
|
inline |
Gets maximum key from the map.
The function returns nullptr if the map is empty
|
inline |
Gets minimum key from the map.
If the map is empty the function returns nullptr
|
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. User-defined functor func should guarantee that during changing item's value no any other changes could be made on this map's item by concurrent threads.
The key_type should be constructible from value of type K.
The function allows to split creating of new item into three 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 |
UPdates data by key.
The operation inserts new item if key is not found in the map and bInsert is true. Otherwise, if key is found, the function returns an iterator that points to item found.
Returns std::pair<iterator, bool> where first is an iterator pointing to item found or inserted or end() if key is not found and insertion is not allowed (bInsert is false), second is true if new item has been added or false if the item already exists.