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