Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_splitlist_map_dhp.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_map.h"
32 #include <cds/container/michael_list_dhp.h>
33 #include <cds/container/split_list_map.h>
34
35 namespace map {
36
37     namespace {
38         struct DHP_cmp_traits: public cc::split_list::traits
39         {
40             typedef cc::michael_list_tag                ordered_list;
41             typedef HashMapHdrTest::hash_int            hash;
42             typedef HashMapHdrTest::simple_item_counter item_counter;
43             typedef cc::opt::v::relaxed_ordering        memory_model;
44             enum { dynamic_bucket_table = false };
45
46             struct ordered_list_traits: public cc::michael_list::traits
47             {
48                 typedef HashMapHdrTest::cmp   compare;
49             };
50         };
51
52         struct DHP_less_traits: public cc::split_list::traits
53         {
54             typedef cc::michael_list_tag                ordered_list;
55             typedef HashMapHdrTest::hash_int            hash;
56             typedef HashMapHdrTest::simple_item_counter item_counter;
57             typedef cc::opt::v::sequential_consistent                      memory_model;
58             enum { dynamic_bucket_table = true };
59
60             struct ordered_list_traits: public cc::michael_list::traits
61             {
62                 typedef HashMapHdrTest::less   less;
63             };
64         };
65
66         struct DHP_cmpmix_traits: public cc::split_list::traits
67         {
68             typedef cc::michael_list_tag                ordered_list;
69             typedef HashMapHdrTest::hash_int            hash;
70             typedef HashMapHdrTest::simple_item_counter item_counter;
71
72             struct ordered_list_traits: public cc::michael_list::traits
73             {
74                 typedef HashMapHdrTest::cmp   compare;
75                 typedef std::less<HashMapHdrTest::key_type>     less;
76             };
77         };
78
79         struct DHP_cmpmix_stat_traits : public DHP_cmpmix_traits
80         {
81             typedef cc::split_list::stat<> stat;
82         };
83     }
84
85     void HashMapHdrTest::Split_DHP_cmp()
86     {
87         // traits-based version
88         typedef cc::SplitListMap< cds::gc::DHP, key_type, value_type, DHP_cmp_traits > map_type;
89         test_int< map_type >();
90
91         // option-based version
92         typedef cc::SplitListMap< cds::gc::DHP,
93             key_type,
94             value_type,
95             cc::split_list::make_traits<
96                 cc::split_list::ordered_list<cc::michael_list_tag>
97                 ,cc::opt::hash< hash_int >
98                 ,cc::opt::item_counter< simple_item_counter >
99                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
100                 ,cc::split_list::dynamic_bucket_table< true >
101                 ,cc::split_list::ordered_list_traits<
102                     cc::michael_list::make_traits<
103                         cc::opt::compare< cmp >
104                     >::type
105                 >
106             >::type
107         > opt_map;
108         test_int< opt_map >();
109     }
110
111     void HashMapHdrTest::Split_DHP_less()
112     {
113         // traits-based version
114         typedef cc::SplitListMap< cds::gc::DHP, key_type, value_type, DHP_less_traits > map_type;
115         test_int< map_type >();
116
117         // option-based version
118         typedef cc::SplitListMap< cds::gc::DHP,
119             key_type,
120             value_type,
121             cc::split_list::make_traits<
122                 cc::split_list::ordered_list<cc::michael_list_tag>
123                 ,cc::opt::hash< hash_int >
124                 ,cc::opt::item_counter< simple_item_counter >
125                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
126                 ,cc::split_list::dynamic_bucket_table< false >
127                 ,cc::split_list::ordered_list_traits<
128                     cc::michael_list::make_traits<
129                         cc::opt::less< less >
130                     >::type
131                 >
132             >::type
133         > opt_map;
134         test_int< opt_map >();
135     }
136
137     void HashMapHdrTest::Split_DHP_cmpmix()
138     {
139         // traits-based version
140         typedef cc::SplitListMap< cds::gc::DHP, key_type, value_type, DHP_cmpmix_traits > map_type;
141         test_int< map_type >();
142
143         // option-based version
144         typedef cc::SplitListMap< cds::gc::DHP,
145             key_type,
146             value_type,
147             cc::split_list::make_traits<
148                 cc::split_list::ordered_list<cc::michael_list_tag>
149                 ,cc::opt::hash< hash_int >
150                 ,cc::opt::item_counter< simple_item_counter >
151                 ,cc::split_list::ordered_list_traits<
152                     cc::michael_list::make_traits<
153                     cc::opt::less< std::less<key_type> >
154                         ,cc::opt::compare< cmp >
155                     >::type
156                 >
157             >::type
158         > opt_map;
159         test_int< opt_map >();
160     }
161
162     void HashMapHdrTest::Split_DHP_cmpmix_stat()
163     {
164         // traits-based version
165         typedef cc::SplitListMap< cds::gc::DHP, key_type, value_type, DHP_cmpmix_stat_traits > map_type;
166         test_int< map_type >();
167
168         // option-based version
169         typedef cc::SplitListMap< cds::gc::DHP,
170             key_type,
171             value_type,
172             cc::split_list::make_traits<
173                 cc::split_list::ordered_list<cc::michael_list_tag>
174                 ,cc::opt::hash< hash_int >
175                 ,cc::opt::item_counter< simple_item_counter >
176                 ,cc::opt::stat< cc::split_list::stat<> >
177                 ,cc::split_list::ordered_list_traits<
178                     cc::michael_list::make_traits<
179                     cc::opt::less< std::less<key_type> >
180                         ,cc::opt::compare< cmp >
181                     >::type
182                 >
183             >::type
184         > opt_map;
185         test_int< opt_map >();
186     }
187
188 } // namespace map
189