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