cbdd143125f81cb79564b35cd4bc0bc7ea76b9e5
[libcds.git] / cds / container / details / feldman_hashset_base.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef CDSLIB_CONTAINER_DETAILS_FELDMAN_HASHSET_BASE_H
32 #define CDSLIB_CONTAINER_DETAILS_FELDMAN_HASHSET_BASE_H
33
34 #include <cds/intrusive/details/feldman_hashset_base.h>
35 #include <cds/container/details/base.h>
36
37 namespace cds { namespace container {
38     /// \p FeldmanHashSet related definitions
39     /** @ingroup cds_nonintrusive_helper
40     */
41     namespace feldman_hashset {
42         /// Hash accessor option
43         /**
44             @copydetails cds::intrusive::feldman_hashset::traits::hash_accessor
45         */
46         template <typename Accessor>
47         using hash_accessor = cds::intrusive::feldman_hashset::hash_accessor< Accessor >;
48
49         /// \p FeldmanHashSet internal statistics, see cds::intrusive::feldman_hashset::stat
50         template <typename EventCounter = cds::atomicity::event_counter>
51         using stat = cds::intrusive::feldman_hashset::stat< EventCounter >;
52
53         /// \p FeldmanHashSet empty internal statistics
54         typedef cds::intrusive::feldman_hashset::empty_stat empty_stat;
55
56         /// Bit-wise memcmp-based comparator for hash value \p T
57         template <typename T>
58         using bitwise_compare = cds::intrusive::feldman_hashset::bitwise_compare< T >;
59
60         /// \p FeldmanHashSet level statistics
61         typedef cds::intrusive::feldman_hashset::level_statistics level_statistics;
62
63         /// \p FeldmanHashSet traits
64         struct traits
65         {
66             /// Mandatory functor to get hash value from data node
67             /**
68                 @copydetails cds::intrusive::feldman_hashset::traits::hash_accessor
69             */
70             typedef cds::opt::none hash_accessor;
71
72             /// Hash comparing functor
73             /**
74                 @copydetails cds::intrusive::feldman_hashset::traits::compare
75             */
76             typedef cds::opt::none compare;
77
78             /// Specifies binary predicate used for hash compare.
79             /**
80                 @copydetails cds::intrusive::feldman_hashset::traits::less
81             */
82             typedef cds::opt::none less;
83
84             /// Item counter
85             /**
86                 @copydetails cds::intrusive::feldman_hashset::traits::item_counter
87             */
88             typedef cds::atomicity::item_counter item_counter;
89
90             /// Item allocator
91             /**
92                 Default is \ref CDS_DEFAULT_ALLOCATOR
93             */
94             typedef CDS_DEFAULT_ALLOCATOR allocator;
95
96             /// Array node allocator
97             /**
98                 @copydetails cds::intrusive::feldman_hashset::traits::node_allocator
99             */
100             typedef CDS_DEFAULT_ALLOCATOR node_allocator;
101
102             /// C++ memory ordering model
103             /**
104                 @copydetails cds::intrusive::feldman_hashset::traits::memory_model
105             */
106             typedef cds::opt::v::relaxed_ordering memory_model;
107
108             /// Back-off strategy
109             typedef cds::backoff::Default back_off;
110
111             /// Internal statistics
112             /**
113                 @copydetails cds::intrusive::feldman_hashset::traits::stat
114             */
115             typedef empty_stat stat;
116
117             /// RCU deadlock checking policy (only for \ref cds_container_FeldmanHashSet_rcu "RCU-based FeldmanHashSet")
118             /**
119                 @copydetails cds::intrusive::feldman_hashset::traits::rcu_check_deadlock
120             */
121             typedef cds::opt::v::rcu_throw_deadlock rcu_check_deadlock;
122         };
123
124         /// Metafunction converting option list to \p feldman_hashset::traits
125         /**
126             Supported \p Options are:
127             - \p feldman_hashset::hash_accessor - mandatory option, hash accessor functor.
128                 @copydetails traits::hash_accessor
129             - \p opt::allocator - item allocator
130                 @copydetails traits::allocator
131             - \p opt::node_allocator - array node allocator.
132                 @copydetails traits::node_allocator
133             - \p opt::compare - hash comparison functor. No default functor is provided.
134                 If the option is not specified, the \p opt::less is used.
135             - \p opt::less - specifies binary predicate used for hash comparison.
136                 @copydetails cds::container::feldman_hashset::traits::less
137             - \p opt::back_off - back-off strategy used. If the option is not specified, the \p cds::backoff::Default is used.
138             - \p opt::item_counter - the type of item counting feature.
139                 @copydetails cds::intrusive::feldman_hashset::traits::item_counter
140             - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
141                 or \p opt::v::sequential_consistent (sequentially consisnent memory model).
142             - \p opt::stat - internal statistics. By default, it is disabled (\p feldman_hashset::empty_stat).
143                 To enable it use \p feldman_hashset::stat
144             - \p opt::rcu_check_deadlock - a deadlock checking policy for \ref cds_intrusive_FeldmanHashSet_rcu "RCU-based FeldmanHashSet"
145                 Default is \p opt::v::rcu_throw_deadlock
146         */
147         template <typename... Options>
148         struct make_traits
149         {
150 #   ifdef CDS_DOXYGEN_INVOKED
151             typedef implementation_defined type ;   ///< Metafunction result
152 #   else
153             typedef typename cds::opt::make_options<
154                 typename cds::opt::find_type_traits< traits, Options... >::type
155                 ,Options...
156             >::type   type;
157 #   endif
158         };
159     } // namespace feldman_hashset
160
161     //@cond
162     // Forward declaration
163     template < class GC, typename T, class Traits = cds::container::feldman_hashset::traits >
164     class FeldmanHashSet;
165     //@endcond
166
167     //@cond
168     namespace details {
169
170         template <typename GC, typename T, typename Traits>
171         struct make_feldman_hashset
172         {
173             typedef GC      gc;
174             typedef T       value_type;
175             typedef Traits  original_traits;
176
177             typedef cds::details::Allocator< value_type, typename original_traits::allocator > cxx_node_allocator;
178
179             struct node_disposer
180             {
181                 void operator()( value_type * p ) const
182                 {
183                     cxx_node_allocator().Delete( p );
184                 }
185             };
186
187             struct intrusive_traits: public original_traits
188             {
189                 typedef node_disposer disposer;
190             };
191
192             // Metafunction result
193             typedef cds::intrusive::FeldmanHashSet< GC, T, intrusive_traits > type;
194         };
195     } // namespace details
196     //@endcond
197
198 }} // namespace cds::container
199
200 #endif // #ifndef CDSLIB_CONTAINER_DETAILS_FELDMAN_HASHSET_BASE_H