2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #include "test_intrusive_split_iterable_set_hp.h"
33 #include <cds/intrusive/iterable_list_hp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::HP gc_type;
41 class IntrusiveSplitListIterableSet_HP : public cds_test::intrusive_split_iterable_set_hp
44 typedef cds_test::intrusive_split_iterable_set_hp base_class;
45 typedef base_class::item_type< ci::split_list::node<void>> item_type;
50 struct list_traits : public ci::iterable_list::traits
52 typedef ci::IterableList< gc_type, item_type, list_traits > list_type;
53 typedef ci::SplitListSet< gc_type, list_type > set_type;
56 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 3, 1, 16 );
57 cds::threading::Manager::attachThread();
62 cds::threading::Manager::detachThread();
63 cds::gc::hp::GarbageCollector::Destruct( true );
68 TEST_F( IntrusiveSplitListIterableSet_HP, cmp )
70 typedef ci::IterableList< gc_type
72 ,ci::iterable_list::make_traits<
73 ci::opt::compare< cmp<item_type> >
74 ,ci::opt::disposer< mock_disposer >
78 typedef ci::SplitListSet< gc_type, bucket_type,
79 ci::split_list::make_traits<
80 ci::opt::hash< hash_int >
84 set_type s( kSize, 2 );
88 TEST_F( IntrusiveSplitListIterableSet_HP, less )
90 typedef ci::IterableList< gc_type
92 ,ci::iterable_list::make_traits<
93 ci::opt::less< less<item_type> >
94 ,ci::opt::disposer< mock_disposer >
98 typedef ci::SplitListSet< gc_type, bucket_type,
99 ci::split_list::make_traits<
100 ci::opt::hash< hash_int >
104 set_type s( kSize, 2 );
108 TEST_F( IntrusiveSplitListIterableSet_HP, cmpmix )
110 struct list_traits : public ci::iterable_list::traits
112 typedef base_class::less<item_type> less;
113 typedef cmp<item_type> compare;
114 typedef mock_disposer disposer;
116 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
118 struct set_traits : public ci::split_list::traits
120 typedef hash_int hash;
121 typedef simple_item_counter item_counter;
123 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
125 set_type s( kSize, 2 );
129 TEST_F( IntrusiveSplitListIterableSet_HP, free_list )
131 struct list_traits: public ci::iterable_list::traits
133 typedef base_class::less<item_type> less;
134 typedef cmp<item_type> compare;
135 typedef mock_disposer disposer;
137 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
139 struct set_traits: public ci::split_list::traits
141 typedef hash_int hash;
142 typedef ci::FreeList free_list;
144 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
146 set_type s( kSize, 2 );
150 TEST_F( IntrusiveSplitListIterableSet_HP, static_bucket_table )
152 struct list_traits: public ci::iterable_list::traits
154 typedef base_class::less<item_type> less;
155 typedef cmp<item_type> compare;
156 typedef mock_disposer disposer;
158 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
160 struct set_traits: public ci::split_list::traits
162 typedef hash_int hash;
164 dynamic_bucket_table = false
167 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
169 set_type s( kSize, 2 );
173 TEST_F( IntrusiveSplitListIterableSet_HP, static_bucket_table_free_list )
175 struct list_traits: public ci::iterable_list::traits
177 typedef base_class::less<item_type> less;
178 typedef cmp<item_type> compare;
179 typedef mock_disposer disposer;
181 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
183 struct set_traits: public ci::split_list::traits
185 typedef hash_int hash;
187 dynamic_bucket_table = false
189 typedef ci::FreeList free_list;
191 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
193 set_type s( kSize, 2 );
197 TEST_F( IntrusiveSplitListIterableSet_HP, list_stat )
199 struct list_traits: public ci::iterable_list::traits
201 typedef base_class::less<item_type> less;
202 typedef cmp<item_type> compare;
203 typedef mock_disposer disposer;
204 typedef ci::iterable_list::stat<> stat;
206 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
208 struct set_traits: public ci::split_list::traits
210 typedef hash_int hash;
211 typedef simple_item_counter item_counter;
213 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
215 set_type s( kSize, 2 );
217 EXPECT_GE( s.list_statistics().m_nInsertSuccess, 0u );
220 TEST_F( IntrusiveSplitListIterableSet_HP, stat )
222 struct list_traits: public ci::iterable_list::traits
224 typedef base_class::less<item_type> less;
225 typedef cmp<item_type> compare;
226 typedef mock_disposer disposer;
228 typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
230 struct set_traits: public ci::split_list::traits
232 typedef hash_int hash;
233 typedef simple_item_counter item_counter;
234 typedef ci::split_list::stat<> stat;
236 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
238 set_type s( kSize, 2 );
240 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
243 TEST_F( IntrusiveSplitListIterableSet_HP, derived_list )
245 class bucket_type: public ci::IterableList< gc_type
247 ,ci::iterable_list::make_traits<
248 ci::opt::compare< cmp<item_type> >
249 ,ci::opt::disposer< mock_disposer >
254 typedef ci::SplitListSet< gc_type, bucket_type,
255 ci::split_list::make_traits<
256 ci::opt::hash< hash_int >
260 set_type s( kSize, 2 );