Updated copyright
[libcds.git] / test / unit / set / michael_lazy_nogc.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-2017
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_set_nogc.h"
32
33 #include <cds/container/lazy_list_nogc.h>
34 #include <cds/container/michael_set_nogc.h>
35
36 namespace {
37     namespace cc = cds::container;
38     typedef cds::gc::nogc gc_type;
39
40     class MichaelLazySet_NoGC : public cds_test::container_set_nogc
41     {
42     protected:
43         typedef cds_test::container_set_nogc base_class;
44
45         //void SetUp()
46         //{}
47
48         //void TearDown()
49         //{}
50     };
51
52     TEST_F( MichaelLazySet_NoGC, compare )
53     {
54         typedef cc::LazyList< gc_type, int_item,
55             typename cc::lazy_list::make_traits<
56                 cds::opt::compare< cmp >
57             >::type
58         > list_type;
59
60         typedef cc::MichaelHashSet< gc_type, list_type,
61             typename cc::michael_set::make_traits<
62                 cds::opt::hash< hash_int >
63             >::type
64         > set_type;
65
66         set_type s( kSize, 2 );
67         test( s );
68     }
69
70     TEST_F( MichaelLazySet_NoGC, less )
71     {
72         typedef cc::LazyList< gc_type, int_item,
73             typename cc::lazy_list::make_traits<
74                 cds::opt::less< base_class::less >
75             >::type
76         > list_type;
77
78         typedef cc::MichaelHashSet< gc_type, list_type,
79             typename cc::michael_set::make_traits<
80                 cds::opt::hash< hash_int >
81             >::type
82         > set_type;
83
84         set_type s( kSize, 2 );
85         test( s );
86     }
87
88     TEST_F( MichaelLazySet_NoGC, cmpmix )
89     {
90         struct list_traits : public cc::lazy_list::traits
91         {
92             typedef base_class::less less;
93             typedef cmp compare;
94         };
95         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
96
97         typedef cc::MichaelHashSet< gc_type, list_type,
98             typename cc::michael_set::make_traits<
99                 cds::opt::hash< hash_int >
100             >::type
101         > set_type;
102
103         set_type s( kSize, 2 );
104         test( s );
105     }
106
107     TEST_F( MichaelLazySet_NoGC, item_counting )
108     {
109         struct list_traits : public cc::lazy_list::traits
110         {
111             typedef cmp compare;
112         };
113         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
114
115         struct set_traits: public cc::michael_set::traits
116         {
117             typedef hash_int hash;
118             typedef simple_item_counter item_counter;
119         };
120         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
121
122         set_type s( kSize, 3 );
123         test( s );
124     }
125
126     TEST_F( MichaelLazySet_NoGC, backoff )
127     {
128         struct list_traits : public cc::lazy_list::traits
129         {
130             typedef cmp compare;
131             typedef cds::backoff::exponential<cds::backoff::pause, cds::backoff::yield> back_off;
132         };
133         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
134
135         struct set_traits : public cc::michael_set::traits
136         {
137             typedef hash_int hash;
138             typedef cds::atomicity::item_counter item_counter;
139         };
140         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
141
142         set_type s( kSize, 4 );
143         test( s );
144     }
145
146     TEST_F( MichaelLazySet_NoGC, seq_cst )
147     {
148         struct list_traits : public cc::lazy_list::traits
149         {
150             typedef base_class::less less;
151             typedef cds::backoff::pause back_off;
152             typedef cds::opt::v::sequential_consistent memory_model;
153         };
154         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
155
156         struct set_traits : public cc::michael_set::traits
157         {
158             typedef hash_int hash;
159             typedef cds::atomicity::item_counter item_counter;
160         };
161         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
162
163         set_type s( kSize, 4 );
164         test( s );
165     }
166
167     TEST_F( MichaelLazySet_NoGC, mutex )
168     {
169         struct list_traits : public cc::lazy_list::traits
170         {
171             typedef base_class::less less;
172             typedef cds::backoff::pause back_off;
173             typedef std::mutex lock_type;
174         };
175         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
176
177         struct set_traits : public cc::michael_set::traits
178         {
179             typedef hash_int hash;
180             typedef cds::atomicity::item_counter item_counter;
181         };
182         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
183
184         set_type s( kSize, 4 );
185         test( s );
186     }
187
188     TEST_F( MichaelLazySet_NoGC, stat )
189     {
190         struct list_traits: public cc::lazy_list::traits
191         {
192             typedef base_class::less less;
193             typedef cds::backoff::pause back_off;
194             typedef cc::lazy_list::stat<> stat;
195         };
196         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
197
198         struct set_traits: public cc::michael_set::traits
199         {
200             typedef hash_int hash;
201             typedef cds::atomicity::item_counter item_counter;
202         };
203         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
204
205         set_type s( kSize, 4 );
206         test( s );
207         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
208     }
209
210     TEST_F( MichaelLazySet_NoGC, wrapped_stat )
211     {
212         struct list_traits: public cc::lazy_list::traits
213         {
214             typedef base_class::less less;
215             typedef cds::backoff::pause back_off;
216             typedef cc::lazy_list::wrapped_stat<> stat;
217         };
218         typedef cc::LazyList< gc_type, int_item, list_traits > list_type;
219
220         struct set_traits: public cc::michael_set::traits
221         {
222             typedef hash_int hash;
223             typedef cds::atomicity::item_counter item_counter;
224         };
225         typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
226
227         set_type s( kSize, 4 );
228         test( s );
229         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
230     }
231
232 } // namespace