Fixed container::StripedSet::emplace() bug
[libcds.git] / tests / test-hdr / set / hdr_intrusive_striped_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::Striped_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::striping<> >
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::Striped_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         > set_type;
69
70         test<set_type>();
71     }
72
73     void IntrusiveStripedSetHdrTest::Striped_slist_basehook_cmpmix()
74     {
75         typedef ci::StripedSet<
76             bi::slist<base_item_type>
77             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
78             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
79             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
80         > set_type;
81
82         static_assert( (std::is_same<
83             IntrusiveStripedSetHdrTest::cmp<base_item_type>
84             ,set_type::bucket_type::key_comparator
85         >::value), "Key compare function selection error" );
86
87         test<set_type>();
88     }
89
90     void IntrusiveStripedSetHdrTest::Striped_slist_basehook_bucket_threshold()
91     {
92         typedef ci::StripedSet<
93             bi::slist<base_item_type>
94             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
95             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
96             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
97             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<8> >
98         > set_type;
99
100         static_assert( (std::is_same<
101             IntrusiveStripedSetHdrTest::cmp<base_item_type>
102             ,set_type::bucket_type::key_comparator
103         >::value), "Key compare function selection error" );
104
105         test<set_type>();
106     }
107
108     void IntrusiveStripedSetHdrTest::Striped_slist_basehook_bucket_threshold_rt()
109     {
110         typedef ci::StripedSet<
111             bi::slist<base_item_type>
112             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
113             ,co::less< IntrusiveStripedSetHdrTest::less<base_item_type> >
114             ,co::compare< IntrusiveStripedSetHdrTest::cmp<base_item_type> >
115             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
116         > set_type;
117
118         static_assert( (std::is_same<
119             IntrusiveStripedSetHdrTest::cmp<base_item_type>
120             ,set_type::bucket_type::key_comparator
121         >::value), "Key compare function selection error" );
122
123         set_type s( 128, ci::striped_set::single_bucket_size_threshold<0>(4) );
124         test_with( s );
125     }
126
127     void IntrusiveStripedSetHdrTest::Striped_slist_memberhook_cmp()
128     {
129         typedef ci::StripedSet<
130             bi::slist<
131                 member_item_type
132                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
133             >
134             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
135             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
136         > set_type;
137
138         test<set_type>();
139     }
140
141     void IntrusiveStripedSetHdrTest::Striped_slist_memberhook_less()
142     {
143         typedef ci::StripedSet<
144             bi::slist<
145                 member_item_type
146                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
147             >
148             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
149             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
150         > set_type;
151
152         test<set_type>();
153     }
154
155     void IntrusiveStripedSetHdrTest::Striped_slist_memberhook_cmpmix()
156     {
157         typedef ci::StripedSet<
158             bi::slist<
159                 member_item_type
160                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
161             >
162             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
163             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
164             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
165         > set_type;
166
167         test<set_type>();
168     }
169
170     void IntrusiveStripedSetHdrTest::Striped_slist_memberhook_bucket_threshold()
171     {
172         typedef ci::StripedSet<
173             bi::slist<
174                 member_item_type
175                 , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
176             >
177             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
178             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
179             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
180             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<8> >
181         > set_type;
182
183         static_assert( (std::is_same<
184             IntrusiveStripedSetHdrTest::cmp<member_item_type>
185             ,set_type::bucket_type::key_comparator
186         >::value), "Key compare function selection error" );
187
188         test<set_type>();
189     }
190
191     void IntrusiveStripedSetHdrTest::Striped_slist_memberhook_bucket_threshold_rt()
192     {
193         typedef ci::StripedSet<
194             bi::slist<
195             member_item_type
196             , bi::member_hook< member_item_type, bi::slist_member_hook<>, &member_item_type::hMember>
197             >
198             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
199             ,co::less< IntrusiveStripedSetHdrTest::less<member_item_type> >
200             ,co::compare< IntrusiveStripedSetHdrTest::cmp<member_item_type> >
201             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
202         > set_type;
203
204         static_assert( (std::is_same<
205             IntrusiveStripedSetHdrTest::cmp<member_item_type>
206             ,set_type::bucket_type::key_comparator
207         >::value), "Key compare function selection error" );
208
209         set_type s( 128, ci::striped_set::single_bucket_size_threshold<0>(4) );
210         test_with( s );
211     }
212
213 } // namespace set
214
215