Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_striped_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::Striped_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 namespace map {
50
51     namespace {
52         typedef boost::container::slist<StripedMapHdrTest::pair_type> sequence_t;
53
54         struct my_copy_policy {
55             typedef sequence_t::iterator iterator;
56
57             void operator()( sequence_t& list, iterator itInsert, iterator itWhat )
58             {
59                 list.insert_after( itInsert, StripedMapHdrTest::pair_type( std::make_pair(itWhat->first, itWhat->second )));
60             }
61         };
62     }
63
64     void StripedMapHdrTest::Striped_slist()
65     {
66         CPPUNIT_MESSAGE( "cmp");
67         typedef cc::StripedMap< sequence_t
68             , co::hash< hash_int >
69             , co::compare< cmp >
70             ,co::mutex_policy< cc::striped_set::striping<> >
71         >   map_cmp;
72         test_striped2< map_cmp >();
73
74         CPPUNIT_MESSAGE( "less");
75         typedef cc::StripedMap< sequence_t
76             , co::hash< hash_int >
77             , co::less< less >
78         >   map_less;
79         test_striped2< map_less >();
80
81         CPPUNIT_MESSAGE( "cmpmix");
82         typedef cc::StripedMap< sequence_t
83             , co::hash< hash_int >
84             , co::compare< cmp >
85             , co::less< less >
86         >   map_cmpmix;
87         test_striped2< map_cmpmix >();
88
89         // Spinlock as lock policy
90         CPPUNIT_MESSAGE( "spinlock");
91         typedef cc::StripedMap< sequence_t
92             , co::hash< hash_int >
93             , co::less< less >
94             , co::mutex_policy< cc::striped_set::striping<cds::sync::spin> >
95         >   map_spin;
96         test_striped2< map_spin >();
97
98         // Resizing policy
99         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
100         {
101             typedef cc::StripedMap< sequence_t
102                 , co::hash< hash_int >
103                 , co::less< less >
104                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
105             >   pair_type_less_resizing_lf;
106             pair_type_less_resizing_lf m(30, cc::striped_set::load_factor_resizing<0>(8) );
107             test_striped_with(m);
108         }
109
110         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
111         typedef cc::StripedMap< sequence_t
112             , co::hash< hash_int >
113             , co::less< less >
114             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
115         >   map_less_resizing_lf16;
116         test_striped2< map_less_resizing_lf16 >();
117
118         {
119             CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
120             typedef cc::StripedMap< sequence_t
121                 , co::hash< hash_int >
122                 , co::less< less >
123                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
124             >   map_less_resizing_sbt;
125             map_less_resizing_sbt m(30, cc::striped_set::single_bucket_size_threshold<0>(8));
126             test_striped_with(m);
127         }
128
129         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
130         typedef cc::StripedMap< sequence_t
131             , co::hash< hash_int >
132             , co::less< less >
133             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
134         >   map_less_resizing_sbt16;
135         test_striped2< map_less_resizing_sbt16 >();
136
137         // Copy policy
138         CPPUNIT_MESSAGE( "copy_item");
139         typedef cc::StripedMap< sequence_t
140             , co::hash< hash_int >
141             , co::less< less >
142             , co::copy_policy< cc::striped_set::copy_item >
143         >   set_copy_item;
144         test_striped2< set_copy_item >();
145
146         CPPUNIT_MESSAGE( "swap_item");
147         typedef cc::StripedMap< sequence_t
148             , co::hash< hash_int >
149             , co::less< less >
150             , co::copy_policy< cc::striped_set::swap_item >
151         >   set_swap_item;
152         test_striped2< set_swap_item >();
153
154         CPPUNIT_MESSAGE( "move_item");
155         typedef cc::StripedMap< sequence_t
156             , co::hash< hash_int >
157             , co::less< less >
158             , co::copy_policy< cc::striped_set::move_item >
159         >   set_move_item;
160         test_striped2< set_move_item >();
161
162         CPPUNIT_MESSAGE( "special copy_item");
163         typedef cc::StripedMap< sequence_t
164             , co::hash< hash_int >
165             , co::compare< cmp >
166             , co::copy_policy< my_copy_policy >
167         >   set_special_copy_item;
168         test_striped2< set_special_copy_item >();
169     }
170
171 }   // namespace map
172
173 #else // BOOST_VERSION < 104800
174
175 namespace map {
176     void StripedMapHdrTest::Striped_slist()
177     {
178         CPPUNIT_MESSAGE( "Skipped; for boost::container::slist you should use boost version 1.48 or above" );
179     }
180 }
181 #endif  // BOOST_VERSION