Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / map / hdr_refinable_hashmap_hashmap_std.cpp
1 //$$CDS-header$$
2
3 #include "map/hdr_striped_map.h"
4 #include <cds/container/striped_map/std_hash_map.h>
5 #include <cds/container/striped_map.h>
6 #include <cds/lock/spinlock.h>
7
8 #if !((CDS_COMPILER == CDS_COMPILER_MSVC || CDS_COMPILER == CDS_COMPILER_INTEL) && _MSC_VER < 1600)
9
10 namespace map {
11
12     namespace {
13         typedef std::unordered_map< StripedMapHdrTest::key_type, StripedMapHdrTest::value_type > map_t;
14
15         struct my_copy_policy {
16             typedef map_t::iterator iterator;
17
18             void operator()( map_t& m, iterator itInsert, iterator itWhat )
19             {
20                 m.insert( std::make_pair(itWhat->first, itWhat->second ) );
21             }
22         };
23     }
24
25     void StripedMapHdrTest::Refinable_hashmap()
26     {
27         CPPUNIT_MESSAGE( "cmp");
28         typedef cc::StripedMap< map_t
29             ,co::mutex_policy< cc::striped_set::refinable<> >
30             , co::hash< hash_int >
31             , co::compare< cmp >
32         >   map_cmp;
33         test_striped< map_cmp >();
34
35         CPPUNIT_MESSAGE( "less");
36         typedef cc::StripedMap< map_t
37             ,co::mutex_policy< cc::striped_set::refinable<> >
38             , co::hash< hash_int >
39             , co::less< less >
40         >   map_less;
41         test_striped< map_less >();
42
43         CPPUNIT_MESSAGE( "cmpmix");
44         typedef cc::StripedMap< map_t
45             ,co::mutex_policy< cc::striped_set::refinable<> >
46             , co::hash< hash_int >
47             , co::compare< cmp >
48             , co::less< less >
49         >   map_cmpmix;
50         test_striped< map_cmpmix >();
51
52         // Spinlock as lock policy
53         CPPUNIT_MESSAGE( "spinlock");
54         typedef cc::StripedMap< map_t
55             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::Spin> >
56             , co::hash< hash_int >
57             , co::less< less >
58         >   map_spin;
59         test_striped< map_spin >();
60
61         // Resizing policy
62         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
63         {
64             typedef cc::StripedMap< map_t
65                 ,co::mutex_policy< cc::striped_set::refinable<> >
66                 , co::hash< hash_int >
67                 , co::less< less >
68                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
69             >   map_less_resizing_lf;
70             map_less_resizing_lf m(30, cc::striped_set::load_factor_resizing<0>(1024));
71             test_striped_with(m);
72         }
73
74         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
75         typedef cc::StripedMap< map_t
76             ,co::mutex_policy< cc::striped_set::refinable<> >
77             , co::hash< hash_int >
78             , co::less< less >
79             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
80         >   map_less_resizing_lf16;
81         test_striped< map_less_resizing_lf16 >();
82
83         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
84         {
85             typedef cc::StripedMap< map_t
86                 ,co::mutex_policy< cc::striped_set::refinable<> >
87                 , co::hash< hash_int >
88                 , co::compare< cmp >
89                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
90             >   map_less_resizing_sbt;
91             map_less_resizing_sbt m(30, cc::striped_set::single_bucket_size_threshold<0>(1024));
92             test_striped_with(m);
93         }
94
95         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
96         typedef cc::StripedMap< map_t
97             ,co::mutex_policy< cc::striped_set::refinable<> >
98             , co::hash< hash_int >
99             , co::less< less >
100             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
101         >   map_less_resizing_sbt16;
102         test_striped< map_less_resizing_sbt16 >();
103
104         // Copy policy
105         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
106         typedef cc::StripedMap< map_t
107             ,co::mutex_policy< cc::striped_set::refinable<> >
108             , co::hash< hash_int >
109             , co::less< less >
110             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
111             , co::copy_policy< cc::striped_set::copy_item >
112         >   set_copy_item;
113         test_striped< set_copy_item >();
114
115         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
116         typedef cc::StripedMap< map_t
117             ,co::mutex_policy< cc::striped_set::refinable<> >
118             , co::hash< hash_int >
119             , co::less< less >
120             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
121             , co::copy_policy< cc::striped_set::swap_item >
122         >   set_swap_item;
123         test_striped< set_swap_item >();
124
125         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
126         typedef cc::StripedMap< map_t
127             ,co::mutex_policy< cc::striped_set::refinable<> >
128             , co::hash< hash_int >
129             , co::less< less >
130             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
131             , co::copy_policy< cc::striped_set::move_item >
132         >   set_move_item;
133         test_striped< set_move_item >();
134
135         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_policy");
136         typedef cc::StripedMap< map_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::load_factor_resizing<256> >
141             , co::copy_policy< my_copy_policy >
142         >   set_special_copy_item;
143         test_striped< set_special_copy_item >();
144     }
145
146 }   // namespace map
147
148 #endif // #if !(CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION < 1600)