Added container::SlitListSet<HP> based on IterableList
[libcds.git] / test / unit / intrusive-set / intrusive_split_iterable_dhp.cpp
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 #include "test_intrusive_split_iterable_set_hp.h"
32
33 #include <cds/intrusive/iterable_list_dhp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
36
37 namespace {
38     namespace ci = cds::intrusive;
39     typedef cds::gc::DHP gc_type;
40
41     class IntrusiveSplitListIterableSet_DHP : public cds_test::intrusive_split_iterable_set_hp
42     {
43     protected:
44         typedef cds_test::intrusive_split_iterable_set_hp base_class;
45         typedef base_class::item_type< ci::split_list::node<void>> item_type;
46
47     protected:
48         void SetUp()
49         {
50             struct list_traits : public ci::iterable_list::traits
51             {};
52             typedef ci::IterableList< gc_type, item_type, list_traits > list_type;
53             typedef ci::SplitListSet< gc_type, list_type >   set_type;
54
55             cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
56             cds::threading::Manager::attachThread();
57         }
58
59         void TearDown()
60         {
61             cds::threading::Manager::detachThread();
62             cds::gc::dhp::GarbageCollector::Destruct();
63         }
64     };
65
66
67     TEST_F( IntrusiveSplitListIterableSet_DHP, cmp )
68     {
69         typedef ci::IterableList< gc_type
70             , item_type
71             ,ci::iterable_list::make_traits<
72                 ci::opt::compare< cmp<item_type> >
73                 ,ci::opt::disposer< mock_disposer >
74             >::type
75         > bucket_type;
76
77         typedef ci::SplitListSet< gc_type, bucket_type,
78             ci::split_list::make_traits<
79                 ci::opt::hash< hash_int >
80             >::type
81         > set_type;
82
83         set_type s( kSize, 2 );
84         test( s );
85     }
86
87     TEST_F( IntrusiveSplitListIterableSet_DHP, less )
88     {
89         typedef ci::IterableList< gc_type
90             , item_type
91             ,ci::iterable_list::make_traits<
92                 ci::opt::less< less<item_type> >
93                 ,ci::opt::disposer< mock_disposer >
94             >::type
95         > bucket_type;
96
97         typedef ci::SplitListSet< gc_type, bucket_type,
98             ci::split_list::make_traits<
99                 ci::opt::hash< hash_int >
100             >::type
101         > set_type;
102
103         set_type s( kSize, 2 );
104         test( s );
105     }
106
107     TEST_F( IntrusiveSplitListIterableSet_DHP, cmpmix )
108     {
109         struct list_traits : public ci::iterable_list::traits
110         {
111             typedef base_class::less<item_type> less;
112             typedef cmp<item_type> compare;
113             typedef mock_disposer disposer;
114         };
115         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
116
117         struct set_traits : public ci::split_list::traits
118         {
119             typedef hash_int hash;
120             typedef simple_item_counter item_counter;
121         };
122         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
123
124         set_type s( kSize, 2 );
125         test( s );
126     }
127
128     TEST_F( IntrusiveSplitListIterableSet_DHP, free_list )
129     {
130         struct list_traits: public ci::iterable_list::traits
131         {
132             typedef base_class::less<item_type> less;
133             typedef cmp<item_type> compare;
134             typedef mock_disposer disposer;
135         };
136         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
137
138         struct set_traits: public ci::split_list::traits
139         {
140             typedef hash_int hash;
141             typedef ci::FreeList  free_list;
142         };
143         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
144
145         set_type s( kSize, 2 );
146         test( s );
147     }
148
149     TEST_F( IntrusiveSplitListIterableSet_DHP, static_bucket_table )
150     {
151         struct list_traits: public ci::iterable_list::traits
152         {
153             typedef base_class::less<item_type> less;
154             typedef cmp<item_type> compare;
155             typedef mock_disposer disposer;
156         };
157         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
158
159         struct set_traits: public ci::split_list::traits
160         {
161             typedef hash_int hash;
162             enum {
163                 dynamic_bucket_table = false
164             };
165         };
166         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
167
168         set_type s( kSize, 2 );
169         test( s );
170     }
171
172     TEST_F( IntrusiveSplitListIterableSet_DHP, static_bucket_table_free_list )
173     {
174         struct list_traits: public ci::iterable_list::traits
175         {
176             typedef base_class::less<item_type> less;
177             typedef cmp<item_type> compare;
178             typedef mock_disposer disposer;
179         };
180         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
181
182         struct set_traits: public ci::split_list::traits
183         {
184             typedef hash_int hash;
185             enum {
186                 dynamic_bucket_table = false
187             };
188             typedef ci::FreeList free_list;
189         };
190         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
191
192         set_type s( kSize, 2 );
193         test( s );
194     }
195
196     TEST_F( IntrusiveSplitListIterableSet_DHP, list_stat )
197     {
198         struct list_traits: public ci::iterable_list::traits
199         {
200             typedef base_class::less<item_type> less;
201             typedef cmp<item_type> compare;
202             typedef mock_disposer disposer;
203             typedef ci::iterable_list::stat<> stat;
204         };
205         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
206
207         struct set_traits: public ci::split_list::traits
208         {
209             typedef hash_int hash;
210             typedef simple_item_counter item_counter;
211         };
212         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
213
214         set_type s( kSize, 2 );
215         test( s );
216         EXPECT_GE( s.list_statistics().m_nInsertSuccess, 0u );
217     }
218
219     TEST_F( IntrusiveSplitListIterableSet_DHP, stat )
220     {
221         struct list_traits: public ci::iterable_list::traits
222         {
223             typedef base_class::less<item_type> less;
224             typedef cmp<item_type> compare;
225             typedef mock_disposer disposer;
226         };
227         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
228
229         struct set_traits: public ci::split_list::traits
230         {
231             typedef hash_int hash;
232             typedef simple_item_counter item_counter;
233             typedef ci::split_list::stat<> stat;
234         };
235         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
236
237         set_type s( kSize, 2 );
238         test( s );
239         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
240     }
241
242
243     TEST_F( IntrusiveSplitListIterableSet_DHP, bucket_type )
244     {
245         class bucket_type: public ci::IterableList< gc_type
246             , item_type
247             ,ci::iterable_list::make_traits<
248                 ci::opt::compare< cmp<item_type> >
249                 ,ci::opt::disposer< mock_disposer >
250             >::type
251         >
252         {};
253
254         typedef ci::SplitListSet< gc_type, bucket_type,
255             ci::split_list::make_traits<
256                 ci::opt::hash< hash_int >
257             >::type
258         > set_type;
259
260         set_type s( kSize, 2 );
261         test( s );
262     }
263
264 } // namespace