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