Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_refinable_hashset_slist.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_intrusive_striped_set.h"
32 #include <cds/intrusive/striped_set/boost_slist.h>
33 #include <cds/intrusive/striped_set.h>
34
35 #include <type_traits>    // std::is_same
36
37 namespace set {
38     namespace bi = boost::intrusive;
39
40     namespace {
41         typedef IntrusiveStripedSetHdrTest::base_item< bi::slist_base_hook<> > base_item_type;
42         typedef IntrusiveStripedSetHdrTest::member_item< bi::slist_member_hook<> > member_item_type;
43     }
44
45     void IntrusiveStripedSetHdrTest::Refinable_slist_basehook_cmp()
46     {
47         typedef ci::StripedSet<
48             bi::slist<base_item_type>
49             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
50             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
51             ,co::mutex_policy< ci::striped_set::refinable<> >
52         > set_type;
53
54         static_assert( (std::is_same<
55             IntrusiveStripedSetHdrTest::cmp<base_item_type>
56             ,set_type::bucket_type::key_comparator
57         >::value), "Key compare function selection error" );
58
59         test<set_type>();
60     }
61
62     void IntrusiveStripedSetHdrTest::Refinable_slist_basehook_less()
63     {
64         typedef ci::StripedSet<
65             bi::slist<base_item_type>
66             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
67             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
68             ,co::mutex_policy< ci::striped_set::refinable<> >
69         > set_type;
70
71         test<set_type>();
72     }
73
74     void IntrusiveStripedSetHdrTest::Refinable_slist_basehook_cmpmix()
75     {
76         typedef ci::StripedSet<
77             bi::slist<base_item_type>
78             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
79             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
80             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
81             ,co::mutex_policy< ci::striped_set::refinable<> >
82         > set_type;
83
84         static_assert( (std::is_same<
85             IntrusiveStripedSetHdrTest::cmp<base_item_type>
86             ,set_type::bucket_type::key_comparator
87         >::value), "Key compare function selection error" );
88
89         test<set_type>();
90     }
91
92     void IntrusiveStripedSetHdrTest::Refinable_slist_basehook_bucket_threshold()
93     {
94         typedef ci::StripedSet<
95             bi::slist<base_item_type>
96             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
97             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
98             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
99             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<8> >
100             ,co::mutex_policy< ci::striped_set::refinable<> >
101         > set_type;
102
103         static_assert( (std::is_same<
104             IntrusiveStripedSetHdrTest::cmp<base_item_type>
105             ,set_type::bucket_type::key_comparator
106         >::value), "Key compare function selection error" );
107
108         test<set_type>();
109     }
110
111     void IntrusiveStripedSetHdrTest::Refinable_slist_basehook_bucket_threshold_rt()
112     {
113         typedef ci::StripedSet<
114             bi::slist<base_item_type>
115             ,co::mutex_policy< ci::striped_set::refinable<> >
116             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
117             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
118             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
119             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
120         > set_type;
121
122         static_assert( (std::is_same<
123             IntrusiveStripedSetHdrTest::cmp<base_item_type>
124             ,set_type::bucket_type::key_comparator
125         >::value), "Key compare function selection error" );
126
127         set_type s( 128, ci::striped_set::single_bucket_size_threshold<0>(4) );
128         test_with( s );
129     }
130
131     void IntrusiveStripedSetHdrTest::Refinable_slist_memberhook_cmp()
132     {
133         typedef ci::StripedSet<
134             bi::slist<
135                 member_item_type
136                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
137             >
138             ,co::mutex_policy< ci::striped_set::refinable<> >
139             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
140             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
141         > set_type;
142
143         test<set_type>();
144     }
145
146     void IntrusiveStripedSetHdrTest::Refinable_slist_memberhook_less()
147     {
148         typedef ci::StripedSet<
149             bi::slist<
150                 member_item_type
151                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
152             >
153             ,co::mutex_policy< ci::striped_set::refinable<> >
154             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
155             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
156         > set_type;
157
158         test<set_type>();
159     }
160
161     void IntrusiveStripedSetHdrTest::Refinable_slist_memberhook_cmpmix()
162     {
163         typedef ci::StripedSet<
164             bi::slist<
165                 member_item_type
166                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
167             >
168             ,co::mutex_policy< ci::striped_set::refinable<> >
169             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
170             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
171             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
172         > set_type;
173
174         test<set_type>();
175     }
176
177     void IntrusiveStripedSetHdrTest::Refinable_slist_memberhook_bucket_threshold()
178     {
179         typedef ci::StripedSet<
180             bi::slist<
181                 member_item_type
182                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
183             >
184             ,co::mutex_policy< ci::striped_set::refinable<> >
185             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
186             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
187             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
188             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<8> >
189         > set_type;
190
191         static_assert( (std::is_same<
192             IntrusiveStripedSetHdrTest::cmp<member_item_type>
193             ,set_type::bucket_type::key_comparator
194         >::value), "Key compare function selection error" );
195
196         test<set_type>();
197     }
198
199     void IntrusiveStripedSetHdrTest::Refinable_slist_memberhook_bucket_threshold_rt()
200     {
201         typedef ci::StripedSet<
202             bi::slist<
203                 member_item_type
204                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
205             >
206             ,co::mutex_policy< ci::striped_set::refinable<> >
207             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
208             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
209             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
210             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
211         > set_type;
212
213         static_assert( (std::is_same<
214             IntrusiveStripedSetHdrTest::cmp<member_item_type>
215             ,set_type::bucket_type::key_comparator
216         >::value), "Key compare function selection error" );
217
218         set_type s( 128, ci::striped_set::single_bucket_size_threshold<0>(4) );
219         test_with( s );
220     }
221
222 } // namespace set
223
224