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