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