2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
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_michael_iterable_hp.h"
33 #include <cds/container/iterable_kvlist_dhp.h>
34 #include <cds/container/michael_map.h>
38 namespace cc = cds::container;
39 typedef cds::gc::DHP gc_type;
41 class MichaelIterableMap_DHP: public cds_test::michael_iterable_hp
44 typedef cds_test::michael_iterable_hp base_class;
48 typedef cc::IterableKVList< gc_type, key_type, value_type > list_type;
49 typedef cc::MichaelHashMap< gc_type, list_type > map_type;
51 cds::gc::dhp::GarbageCollector::Construct( 16, map_type::c_nHazardPtrCount );
52 cds::threading::Manager::attachThread();
57 cds::threading::Manager::detachThread();
58 cds::gc::dhp::GarbageCollector::Destruct();
62 TEST_F( MichaelIterableMap_DHP, compare )
64 typedef cc::IterableKVList< gc_type, key_type, value_type,
65 typename cc::iterable_list::make_traits<
66 cds::opt::compare< cmp >
70 typedef cc::MichaelHashMap< gc_type, list_type,
71 typename cc::michael_map::make_traits<
72 cds::opt::hash< hash1 >
76 map_type m( kSize, 2 );
80 TEST_F( MichaelIterableMap_DHP, less )
82 typedef cc::IterableKVList< gc_type, key_type, value_type,
83 typename cc::iterable_list::make_traits<
84 cds::opt::less< less >
88 typedef cc::MichaelHashMap< gc_type, list_type,
89 typename cc::michael_map::make_traits<
90 cds::opt::hash< hash1 >
94 map_type m( kSize, 1 );
98 TEST_F( MichaelIterableMap_DHP, cmpmix )
100 typedef cc::IterableKVList< gc_type, key_type, value_type,
101 typename cc::iterable_list::make_traits<
102 cds::opt::less< less >
103 ,cds::opt::compare< cmp >
107 typedef cc::MichaelHashMap< gc_type, list_type,
108 typename cc::michael_map::make_traits<
109 cds::opt::hash< hash1 >
113 map_type m( kSize, 2 );
117 TEST_F( MichaelIterableMap_DHP, backoff )
119 struct list_traits: public cc::iterable_list::traits
122 typedef cds::backoff::exponential<cds::backoff::pause, cds::backoff::yield> back_off;
124 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
126 struct map_traits: public cc::michael_map::traits
129 typedef cds::atomicity::item_counter item_counter;
131 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
133 map_type m( kSize, 4 );
137 TEST_F( MichaelIterableMap_DHP, seq_cst )
139 struct list_traits: public cc::iterable_list::traits
142 typedef cds::backoff::yield back_off;
143 typedef cds::opt::v::sequential_consistent memory_model;
145 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
147 struct map_traits: public cc::michael_map::traits
151 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
153 map_type s( kSize, 8 );
157 TEST_F( MichaelIterableMap_DHP, stat )
159 struct list_traits: public cc::iterable_list::traits
162 typedef cds::backoff::yield back_off;
163 typedef cc::iterable_list::stat<> stat;
165 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
167 struct map_traits: public cc::michael_map::traits
171 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
173 map_type m( kSize, 8 );
175 EXPECT_GE( m.statistics().m_nInsertSuccess, 0 );
178 TEST_F( MichaelIterableMap_DHP, wrapped_stat )
180 struct list_traits: public cc::iterable_list::traits
183 typedef cc::iterable_list::wrapped_stat<> stat;
185 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
187 struct map_traits: public cc::michael_map::traits
191 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
193 map_type m( kSize, 8 );
195 EXPECT_GE( m.statistics().m_nInsertSuccess, 0 );