Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_striped_hashmap_list.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 #include <cds/container/striped_map/std_list.h>
33 #include <cds/container/striped_map.h>
34 #include <cds/sync/spinlock.h>
35
36 namespace map {
37
38     namespace {
39         typedef std::list<StripedMapHdrTest::pair_type> sequence_t;
40
41         struct my_copy_policy {
42             typedef sequence_t::iterator iterator;
43
44             void operator()( sequence_t& list, iterator itInsert, iterator itWhat )
45             {
46                 list.insert( itInsert, std::make_pair(itWhat->first, itWhat->second ));
47             }
48
49         };
50     }
51
52     void StripedMapHdrTest::Striped_list()
53     {
54         CPPUNIT_MESSAGE( "cmp");
55         typedef cc::StripedMap< sequence_t
56             , co::hash< hash_int >
57             , co::compare< cmp >
58             ,co::mutex_policy< cc::striped_set::striping<> >
59         >   map_cmp;
60         test_striped2< map_cmp >();
61
62         CPPUNIT_MESSAGE( "less");
63         typedef cc::StripedMap< sequence_t
64             , co::hash< hash_int >
65             , co::less< less >
66         >   map_less;
67         test_striped2< map_less >();
68
69         CPPUNIT_MESSAGE( "cmpmix");
70         typedef cc::StripedMap< sequence_t
71             , co::hash< hash_int >
72             , co::compare< cmp >
73             , co::less< less >
74         >   map_cmpmix;
75         test_striped2< map_cmpmix >();
76
77         // Spinlock as lock policy
78         CPPUNIT_MESSAGE( "spinlock");
79         typedef cc::StripedMap< sequence_t
80             , co::hash< hash_int >
81             , co::less< less >
82             , co::mutex_policy< cc::striped_set::striping<cds::sync::spin> >
83         >   map_spin;
84         test_striped2< map_spin >();
85
86         // Resizing policy
87         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
88         {
89             typedef cc::StripedMap< sequence_t
90                 , co::hash< hash_int >
91                 , co::less< less >
92                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
93             >   pair_type_less_resizing_lf;
94             pair_type_less_resizing_lf m(30, cc::striped_set::load_factor_resizing<0>(8) );
95             test_striped_with(m);
96         }
97
98         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
99         typedef cc::StripedMap< sequence_t
100             , co::hash< hash_int >
101             , co::less< less >
102             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
103         >   map_less_resizing_lf16;
104         test_striped2< map_less_resizing_lf16 >();
105
106         {
107             CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
108             typedef cc::StripedMap< sequence_t
109                 , co::hash< hash_int >
110                 , co::less< less >
111                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
112             >   map_less_resizing_sbt;
113             map_less_resizing_sbt m(30, cc::striped_set::single_bucket_size_threshold<0>(8));
114             test_striped_with(m);
115         }
116
117         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
118         typedef cc::StripedMap< sequence_t
119             , co::hash< hash_int >
120             , co::less< less >
121             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
122         >   map_less_resizing_sbt16;
123         test_striped2< map_less_resizing_sbt16 >();
124
125         // Copy policy
126         CPPUNIT_MESSAGE( "copy_item");
127         typedef cc::StripedMap< sequence_t
128             , co::hash< hash_int >
129             , co::less< less >
130             , co::copy_policy< cc::striped_set::copy_item >
131         >   set_copy_item;
132         test_striped2< set_copy_item >();
133
134         CPPUNIT_MESSAGE( "swap_item");
135         typedef cc::StripedMap< sequence_t
136             , co::hash< hash_int >
137             , co::less< less >
138             , co::copy_policy< cc::striped_set::swap_item >
139         >   set_swap_item;
140         test_striped2< set_swap_item >();
141
142         CPPUNIT_MESSAGE( "move_item");
143         typedef cc::StripedMap< sequence_t
144             , co::hash< hash_int >
145             , co::less< less >
146             , co::copy_policy< cc::striped_set::move_item >
147         >   set_move_item;
148         test_striped2< set_move_item >();
149
150         CPPUNIT_MESSAGE( "special copy_item");
151         typedef cc::StripedMap< sequence_t
152             , co::hash< hash_int >
153             , co::compare< cmp >
154             , co::copy_policy< my_copy_policy >
155         >   set_special_copy_item;
156         test_striped2< set_special_copy_item >();
157     }
158
159 }   // namespace map