rename cds::lock namespace to cds::sync, move corresponding .h files
[libcds.git] / tests / test-hdr / map / hdr_striped_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/sync/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
24     void StripedMapHdrTest::Striped_list()
25     {
26         CPPUNIT_MESSAGE( "cmp");
27         typedef cc::StripedMap< sequence_t
28             , co::hash< hash_int >
29             , co::compare< cmp >
30             ,co::mutex_policy< cc::striped_set::striping<> >
31         >   map_cmp;
32         test_striped2< map_cmp >();
33
34         CPPUNIT_MESSAGE( "less");
35         typedef cc::StripedMap< sequence_t
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::hash< hash_int >
44             , co::compare< cmp >
45             , co::less< less >
46         >   map_cmpmix;
47         test_striped2< map_cmpmix >();
48
49         // Spinlock as lock policy
50         CPPUNIT_MESSAGE( "spinlock");
51         typedef cc::StripedMap< sequence_t
52             , co::hash< hash_int >
53             , co::less< less >
54             , co::mutex_policy< cc::striped_set::striping<cds::sync::spin> >
55         >   map_spin;
56         test_striped2< map_spin >();
57
58         // Resizing policy
59         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
60         {
61             typedef cc::StripedMap< sequence_t
62                 , co::hash< hash_int >
63                 , co::less< less >
64                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
65             >   pair_type_less_resizing_lf;
66             pair_type_less_resizing_lf m(30, cc::striped_set::load_factor_resizing<0>(8) );
67             test_striped_with(m);
68         }
69
70         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
71         typedef cc::StripedMap< sequence_t
72             , co::hash< hash_int >
73             , co::less< less >
74             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
75         >   map_less_resizing_lf16;
76         test_striped2< map_less_resizing_lf16 >();
77
78         {
79             CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
80             typedef cc::StripedMap< sequence_t
81                 , co::hash< hash_int >
82                 , co::less< less >
83                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
84             >   map_less_resizing_sbt;
85             map_less_resizing_sbt m(30, cc::striped_set::single_bucket_size_threshold<0>(8));
86             test_striped_with(m);
87         }
88
89         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
90         typedef cc::StripedMap< sequence_t
91             , co::hash< hash_int >
92             , co::less< less >
93             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
94         >   map_less_resizing_sbt16;
95         test_striped2< map_less_resizing_sbt16 >();
96
97         // Copy policy
98         CPPUNIT_MESSAGE( "copy_item");
99         typedef cc::StripedMap< sequence_t
100             , co::hash< hash_int >
101             , co::less< less >
102             , co::copy_policy< cc::striped_set::copy_item >
103         >   set_copy_item;
104         test_striped2< set_copy_item >();
105
106         CPPUNIT_MESSAGE( "swap_item");
107         typedef cc::StripedMap< sequence_t
108             , co::hash< hash_int >
109             , co::less< less >
110             , co::copy_policy< cc::striped_set::swap_item >
111         >   set_swap_item;
112         test_striped2< set_swap_item >();
113
114         CPPUNIT_MESSAGE( "move_item");
115         typedef cc::StripedMap< sequence_t
116             , co::hash< hash_int >
117             , co::less< less >
118             , co::copy_policy< cc::striped_set::move_item >
119         >   set_move_item;
120         test_striped2< set_move_item >();
121
122         CPPUNIT_MESSAGE( "special copy_item");
123         typedef cc::StripedMap< sequence_t
124             , co::hash< hash_int >
125             , co::compare< cmp >
126             , co::copy_policy< my_copy_policy >
127         >   set_special_copy_item;
128         test_striped2< set_special_copy_item >();
129     }
130
131 }   // namespace map