Merge pull request #58 from rfw/patch-1
[libcds.git] / tests / test-hdr / map / hdr_refinable_hashmap_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 "map/hdr_striped_map.h"
32
33 #include <boost/version.hpp>
34 #include <cds/details/defs.h>
35 #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION <= 105500
36 namespace map {
37     void StripedMapHdrTest::Refinable_slist()
38     {
39         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::slist you should use boost version 1.56 or above");
40     }
41 }
42
43 #elif BOOST_VERSION >= 104800
44
45 #include <cds/container/striped_map/boost_slist.h>
46 #include <cds/container/striped_map.h>
47 #include <cds/sync/spinlock.h>
48
49
50 namespace map {
51
52     namespace {
53         typedef boost::container::slist<StripedMapHdrTest::pair_type> sequence_t;
54
55         struct my_copy_policy {
56             typedef sequence_t::iterator iterator;
57
58             void operator()( sequence_t& list, iterator itInsert, iterator itWhat )
59             {
60                 list.insert_after( itInsert, StripedMapHdrTest::pair_type( std::make_pair(itWhat->first, itWhat->second )));
61             }
62         };
63     }
64
65     void StripedMapHdrTest::Refinable_slist()
66     {
67         CPPUNIT_MESSAGE( "cmp");
68         typedef cc::StripedMap< sequence_t
69             ,co::mutex_policy< cc::striped_set::refinable<> >
70             , co::hash< hash_int >
71             , co::compare< cmp >
72         >   map_cmp;
73         test_striped2< map_cmp >();
74
75         CPPUNIT_MESSAGE( "less");
76         typedef cc::StripedMap< sequence_t
77             ,co::mutex_policy< cc::striped_set::refinable<> >
78             , co::hash< hash_int >
79             , co::less< less >
80         >   map_less;
81         test_striped2< map_less >();
82
83         CPPUNIT_MESSAGE( "cmpmix");
84         typedef cc::StripedMap< sequence_t
85             ,co::mutex_policy< cc::striped_set::refinable<> >
86             , co::hash< hash_int >
87             , co::compare< cmp >
88             , co::less< less >
89         >   map_cmpmix;
90         test_striped2< map_cmpmix >();
91
92         // Spinlock as lock policy
93         CPPUNIT_MESSAGE( "spinlock");
94         typedef cc::StripedMap< sequence_t
95             , co::mutex_policy< cc::striped_set::refinable<cds::sync::spin> >
96             , co::hash< hash_int >
97             , co::less< less >
98         >   map_spin;
99         test_striped2< map_spin >();
100
101         // Resizing policy
102         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
103         {
104             typedef cc::StripedMap< sequence_t
105                 ,co::mutex_policy< cc::striped_set::refinable<> >
106                 , co::hash< hash_int >
107                 , co::less< less >
108                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
109             >   pair_type_less_resizing_lf;
110             pair_type_less_resizing_lf m(30, cc::striped_set::load_factor_resizing<0>(8) );
111             test_striped_with(m);
112         }
113
114         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
115         typedef cc::StripedMap< sequence_t
116             ,co::mutex_policy< cc::striped_set::refinable<> >
117             , co::hash< hash_int >
118             , co::less< less >
119             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
120         >   map_less_resizing_lf16;
121         test_striped2< map_less_resizing_lf16 >();
122
123         {
124             CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
125             typedef cc::StripedMap< sequence_t
126                 ,co::mutex_policy< cc::striped_set::refinable<> >
127                 , co::hash< hash_int >
128                 , co::less< less >
129                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
130             >   map_less_resizing_sbt;
131             map_less_resizing_sbt m(30, cc::striped_set::single_bucket_size_threshold<0>(8));
132             test_striped_with(m);
133         }
134
135         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
136         typedef cc::StripedMap< sequence_t
137             ,co::mutex_policy< cc::striped_set::refinable<> >
138             , co::hash< hash_int >
139             , co::less< less >
140             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
141         >   map_less_resizing_sbt16;
142         test_striped2< map_less_resizing_sbt16 >();
143
144         // Copy policy
145         CPPUNIT_MESSAGE( "copy_item");
146         typedef cc::StripedMap< sequence_t
147             ,co::mutex_policy< cc::striped_set::refinable<> >
148             , co::hash< hash_int >
149             , co::less< less >
150             , co::copy_policy< cc::striped_set::copy_item >
151         >   set_copy_item;
152         test_striped2< set_copy_item >();
153
154         CPPUNIT_MESSAGE( "swap_item");
155         typedef cc::StripedMap< sequence_t
156             ,co::mutex_policy< cc::striped_set::refinable<> >
157             , co::hash< hash_int >
158             , co::less< less >
159             , co::copy_policy< cc::striped_set::swap_item >
160         >   set_swap_item;
161         test_striped2< set_swap_item >();
162
163         CPPUNIT_MESSAGE( "move_item");
164         typedef cc::StripedMap< sequence_t
165             , co::hash< hash_int >
166             ,co::mutex_policy< cc::striped_set::refinable<> >
167             , co::less< less >
168             , co::copy_policy< cc::striped_set::move_item >
169         >   set_move_item;
170         test_striped2< set_move_item >();
171
172         CPPUNIT_MESSAGE( "special copy_item");
173         typedef cc::StripedMap< sequence_t
174             , co::hash< hash_int >
175             , co::compare< cmp >
176             ,co::mutex_policy< cc::striped_set::refinable<> >
177             , co::copy_policy< my_copy_policy >
178         >   set_special_copy_item;
179         test_striped2< set_special_copy_item >();
180     }
181 }   // namespace map
182 #else
183
184 namespace map {
185     void StripedMapHdrTest::Refinable_slist()
186     {
187         CPPUNIT_MESSAGE("Skipped; for boost::container::slist you should use boost version 1.48 or above");
188     }
189 } // namespace map
190
191 #endif  // BOOST_VERSION