Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_splitlist_map_lazy_rcu_gpb.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 "map/hdr_map.h"
32 #include <cds/urcu/general_buffered.h>
33 #include <cds/container/lazy_list_rcu.h>
34 #include <cds/container/split_list_map_rcu.h>
35
36 namespace map {
37
38     namespace {
39         typedef cds::urcu::gc< cds::urcu::general_buffered<> >  rcu_type;
40
41         struct RCU_GPB_cmp_traits: public cc::split_list::traits
42         {
43             typedef cc::lazy_list_tag                   ordered_list;
44             typedef HashMapHdrTest::hash_int            hash;
45             typedef HashMapHdrTest::simple_item_counter item_counter;
46             typedef cc::opt::v::relaxed_ordering        memory_model;
47             enum { dynamic_bucket_table = false };
48
49             struct ordered_list_traits: public cc::lazy_list::traits
50             {
51                 typedef HashMapHdrTest::cmp   compare;
52             };
53         };
54
55         struct RCU_GPB_less_traits: public cc::split_list::traits
56         {
57             typedef cc::lazy_list_tag                   ordered_list;
58             typedef HashMapHdrTest::hash_int            hash;
59             typedef HashMapHdrTest::simple_item_counter item_counter;
60             typedef cc::opt::v::sequential_consistent                      memory_model;
61             enum { dynamic_bucket_table = true };
62
63             struct ordered_list_traits: public cc::lazy_list::traits
64             {
65                 typedef HashMapHdrTest::less   less;
66             };
67         };
68
69         struct RCU_cmpmix_traits: public cc::split_list::traits
70         {
71             typedef cc::lazy_list_tag                   ordered_list;
72             typedef HashMapHdrTest::hash_int            hash;
73             typedef HashMapHdrTest::simple_item_counter item_counter;
74
75             struct ordered_list_traits: public cc::lazy_list::traits
76             {
77                 typedef HashMapHdrTest::cmp   compare;
78                 typedef std::less<HashMapHdrTest::key_type>     less;
79             };
80         };
81
82         struct RCU_cmpmix_stat_traits : public RCU_cmpmix_traits
83         {
84             typedef cc::split_list::stat<> stat;
85         };
86     }
87
88     void HashMapHdrTest::Split_Lazy_RCU_GPB_cmp()
89     {
90         // traits-based version
91         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_GPB_cmp_traits > map_type;
92         test_rcu< map_type >();
93
94         // option-based version
95         typedef cc::SplitListMap< rcu_type,
96             key_type,
97             value_type,
98             cc::split_list::make_traits<
99                 cc::split_list::ordered_list<cc::lazy_list_tag>
100                 ,cc::opt::hash< hash_int >
101                 ,cc::opt::item_counter< simple_item_counter >
102                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
103                 ,cc::split_list::dynamic_bucket_table< true >
104                 ,cc::split_list::ordered_list_traits<
105                     cc::lazy_list::make_traits<
106                         cc::opt::compare< cmp >
107                     >::type
108                 >
109             >::type
110         > opt_map;
111         test_rcu< opt_map >();
112     }
113
114     void HashMapHdrTest::Split_Lazy_RCU_GPB_less()
115     {
116         // traits-based version
117         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_GPB_less_traits > map_type;
118         test_rcu< map_type >();
119
120         // option-based version
121         typedef cc::SplitListMap< rcu_type,
122             key_type,
123             value_type,
124             cc::split_list::make_traits<
125                 cc::split_list::ordered_list<cc::lazy_list_tag>
126                 ,cc::opt::hash< hash_int >
127                 ,cc::opt::item_counter< simple_item_counter >
128                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
129                 ,cc::split_list::dynamic_bucket_table< false >
130                 ,cc::split_list::ordered_list_traits<
131                     cc::lazy_list::make_traits<
132                         cc::opt::less< less >
133                     >::type
134                 >
135             >::type
136         > opt_map;
137         test_rcu< opt_map >();
138     }
139
140     void HashMapHdrTest::Split_Lazy_RCU_GPB_cmpmix()
141     {
142         // traits-based version
143         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_cmpmix_traits > map_type;
144         test_rcu< map_type >();
145
146         // option-based version
147         typedef cc::SplitListMap< rcu_type,
148             key_type,
149             value_type,
150             cc::split_list::make_traits<
151                 cc::split_list::ordered_list<cc::lazy_list_tag>
152                 ,cc::opt::hash< hash_int >
153                 ,cc::opt::item_counter< simple_item_counter >
154                 ,cc::split_list::ordered_list_traits<
155                     cc::lazy_list::make_traits<
156                     cc::opt::less< std::less<key_type> >
157                         ,cc::opt::compare< cmp >
158                     >::type
159                 >
160             >::type
161         > opt_map;
162         test_rcu< opt_map >();
163     }
164
165     void HashMapHdrTest::Split_Lazy_RCU_GPB_cmpmix_stat()
166     {
167         // traits-based version
168         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_cmpmix_stat_traits > map_type;
169         test_rcu< map_type >();
170
171         // option-based version
172         typedef cc::SplitListMap< rcu_type,
173             key_type,
174             value_type,
175             cc::split_list::make_traits<
176                 cc::split_list::ordered_list<cc::lazy_list_tag>
177                 ,cc::opt::hash< hash_int >
178                 ,cc::opt::item_counter< simple_item_counter >
179                 ,cc::opt::stat< cc::split_list::stat<> >
180                 ,cc::split_list::ordered_list_traits<
181                     cc::lazy_list::make_traits<
182                     cc::opt::less< std::less<key_type> >
183                         ,cc::opt::compare< cmp >
184                     >::type
185                 >
186             >::type
187         > opt_map;
188         test_rcu< opt_map >();
189     }
190
191 } // namespace map
192