Refactored LazyList<nogc> with ordering option
[libcds.git] / cds / container / details / lazy_list_base.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_DETAILS_LAZY_LIST_BASE_H
4 #define CDSLIB_CONTAINER_DETAILS_LAZY_LIST_BASE_H
5
6 #include <cds/container/details/base.h>
7 #include <cds/intrusive/details/lazy_list_base.h>
8 #include <cds/urcu/options.h>
9
10 namespace cds { namespace container {
11
12     /// LazyList ordered list related definitions
13     /** @ingroup cds_nonintrusive_helper
14     */
15     namespace lazy_list {
16         /// LazyList traits
17         /**
18             Either \p compare or \p less or both must be specified.
19         */
20         struct traits
21         {
22             /// allocator used to allocate new node
23             typedef CDS_DEFAULT_ALLOCATOR   allocator;
24
25             /// Key comparing functor
26             /**
27                 No default functor is provided. If the option is not specified, the \p less is used.
28             */
29             typedef opt::none                       compare;
30
31             /// Specifies binary predicate used for key comparing
32             /**
33                 Default is \p std::less<T>.
34             */
35             typedef opt::none                       less;
36
37             /// Specifies binary functor used for comparing keys for equality
38             /**
39                 No default functor is provided. If \p equal_to option is not spcified, \p compare is used, if \p compare is not
40                 specified, \p less is used.
41             */
42             typedef opt::none                       equal_to;
43
44             /// Specifies list ordering policy.
45             /**
46                 If \p sort is \p true, than list maintains items in sorted order, otherwise items are unordered. Default is \p true.
47                 Note that if \p sort is \p false then lookup operations scan entire list.
48             */
49             static const bool sort = true;
50
51             /// Lock type used to lock modifying items
52             /**
53                 Default is cds::sync::spin
54             */
55             typedef cds::sync::spin                 lock_type;
56
57             /// back-off strategy used
58             typedef cds::backoff::Default           back_off;
59
60             /// Item counting feature; by default, disabled. Use \p cds::atomicity::item_counter to enable item counting
61             typedef atomicity::empty_item_counter     item_counter;
62
63             /// C++ memory ordering model
64             /**
65                 Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
66                 or \p opt::v::sequential_consistent (sequentially consisnent memory model).
67             */
68             typedef opt::v::relaxed_ordering        memory_model;
69
70             /// RCU deadlock checking policy (only for \ref cds_intrusive_LazyList_rcu "RCU-based LazyList")
71             /**
72                 List of available options see \p opt::rcu_check_deadlock
73             */
74             typedef opt::v::rcu_throw_deadlock      rcu_check_deadlock;
75
76             //@cond
77             // LazyKVList: supporting for split-ordered list
78             // key accessor (opt::none = internal key type is equal to user key type)
79             typedef opt::none                       key_accessor;
80
81             //@endcond
82         };
83
84         /// Metafunction converting option list to \p lazy_list::traits
85         /**
86             \p Options are:
87             - \p opt::lock_type - lock type for node-level locking. Default \p is cds::sync::spin. Note that <b>each</b> node
88                 of the list has member of type \p lock_type, therefore, heavy-weighted locking primitive is not
89                 acceptable as candidate for \p lock_type.
90             - \p opt::compare - key compare functor. No default functor is provided.
91                 If the option is not specified, the \p opt::less is used.
92             - \p opt::less - specifies binary predicate used for key compare. Default is \p std::less<T>.
93             - \p opt::equal_to - specifies binary functor for comparing keys for equality. No default is provided. If \p equal_to is
94                 not specified, \p compare is used, if \p compare is not specified, \p less is used.
95             - \p opt::sort - specifies ordering policy. Default value is \p true.
96             - \p opt::back_off - back-off strategy used. If the option is not specified, \p cds::backoff::Default is used.
97             - \p opt::item_counter - the type of item counting feature. Default is disabled (\p atomicity::empty_item_counter).
98                 To enable item counting use \p atomicity::item_counter.
99             - \p opt::allocator - the allocator used for creating and freeing list's item. Default is \ref CDS_DEFAULT_ALLOCATOR macro.
100             - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
101                 or \p opt::v::sequential_consistent (sequentially consisnent memory model).
102         */
103         template <typename... Options>
104         struct make_traits {
105 #   ifdef CDS_DOXYGEN_INVOKED
106             typedef implementation_defined type ;   ///< Metafunction result
107 #   else
108             typedef typename cds::opt::make_options<
109                 typename cds::opt::find_type_traits< traits, Options... >::type
110                 ,Options...
111             >::type   type;
112 #endif
113         };
114
115
116     } // namespace lazy_list
117
118     // Forward declarations
119     template <typename GC, typename T, typename Traits=lazy_list::traits>
120     class LazyList;
121
122     template <typename GC, typename Key, typename Value, typename Traits=lazy_list::traits>
123     class LazyKVList;
124
125     // Tag for selecting lazy list implementation
126     /**
127         This struct is empty and it is used only as a tag for selecting LazyList
128         as ordered list implementation in declaration of some classes.
129
130         See \p split_list::traits::ordered_list as an example.
131     */
132     struct lazy_list_tag
133     {};
134
135 }}  // namespace cds::container
136
137
138 #endif  // #ifndef CDSLIB_CONTAINER_DETAILS_LAZY_LIST_BASE_H