b6a3bce2dc8578ee0a04522749b49c015262b644
[libcds.git] / tests / test-hdr / tree / hdr_ellenbintree_map_hp.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 "tree/hdr_ellenbintree_map.h"
32 #include <cds/container/ellen_bintree_map_hp.h>
33
34 #include "tree/hdr_intrusive_ellen_bintree_pool_hp.h"
35 #include "unit/print_ellenbintree_stat.h"
36
37 namespace tree {
38     namespace cc = cds::container;
39     namespace co = cds::opt;
40     namespace {
41         typedef cds::gc::HP gc_type;
42
43         typedef cc::ellen_bintree::map_node<gc_type, EllenBinTreeMapHdrTest::key_type, EllenBinTreeMapHdrTest::value_type>  tree_leaf_node;
44         typedef cc::ellen_bintree::internal_node< EllenBinTreeMapHdrTest::key_type, tree_leaf_node >                        tree_internal_node;
45         typedef cc::ellen_bintree::update_desc<tree_leaf_node, tree_internal_node>                                          tree_update_desc;
46
47         struct print_stat {
48             template <typename Tree>
49             void operator()( Tree const& t)
50             {
51                 std::cout << t.statistics();
52             }
53         };
54
55     }
56
57     void EllenBinTreeMapHdrTest::EllenBinTree_hp_less()
58     {
59         struct set_traits : public cc::ellen_bintree::traits
60         {
61             typedef EllenBinTreeMapHdrTest::less less;
62         };
63         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type, set_traits > set_type;
64
65         test<set_type, print_stat>();
66     }
67
68     void EllenBinTreeMapHdrTest::EllenBinTree_hp_cmp()
69     {
70         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
71             cc::ellen_bintree::make_map_traits<
72                 co::compare< compare >
73             >::type
74         > set_type;
75
76         test<set_type, print_stat>();
77     }
78
79     void EllenBinTreeMapHdrTest::EllenBinTree_hp_cmpless()
80     {
81         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
82             cc::ellen_bintree::make_map_traits<
83                 co::compare< compare >
84                 ,co::less< less >
85             >::type
86         > set_type;
87
88         test<set_type, print_stat>();
89     }
90
91     void EllenBinTreeMapHdrTest::EllenBinTree_hp_less_ic()
92     {
93         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
94             cc::ellen_bintree::make_map_traits<
95                 co::less< less >
96                 ,co::item_counter< cds::atomicity::item_counter >
97             >::type
98         > set_type;
99
100         test<set_type, print_stat>();
101     }
102
103     void EllenBinTreeMapHdrTest::EllenBinTree_hp_cmp_ic()
104     {
105         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
106             cc::ellen_bintree::make_map_traits<
107                 co::item_counter< cds::atomicity::item_counter >
108                 ,co::compare< compare >
109             >::type
110         > set_type;
111
112         test<set_type, print_stat>();
113     }
114
115     void EllenBinTreeMapHdrTest::EllenBinTree_hp_less_stat()
116     {
117         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
118             cc::ellen_bintree::make_map_traits<
119                 co::less< less >
120                 ,co::stat< cc::ellen_bintree::stat<> >
121             >::type
122         > set_type;
123
124         test<set_type, print_stat>();
125     }
126
127     void EllenBinTreeMapHdrTest::EllenBinTree_hp_cmp_ic_stat()
128     {
129         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
130             cc::ellen_bintree::make_map_traits<
131                 co::item_counter< cds::atomicity::item_counter >
132                 ,co::stat< cc::ellen_bintree::stat<> >
133                 ,co::compare< compare >
134             >::type
135         > set_type;
136
137         test<set_type, print_stat>();
138     }
139
140     void EllenBinTreeMapHdrTest::EllenBinTree_hp_cmp_ic_stat_yield()
141     {
142         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
143             cc::ellen_bintree::make_map_traits<
144                 co::item_counter< cds::atomicity::item_counter >
145                 ,co::stat< cc::ellen_bintree::stat<> >
146                 ,co::compare< compare >
147                 , co::back_off< cds::backoff::yield >
148             >::type
149         > set_type;
150
151         test<set_type, print_stat>();
152     }
153
154     void EllenBinTreeMapHdrTest::EllenBinTree_hp_less_pool()
155     {
156         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
157             cc::ellen_bintree::make_map_traits<
158                 co::less< less >
159                 ,co::node_allocator< cds::memory::pool_allocator< tree_internal_node, ellen_bintree_hp::internal_node_pool_accessor > >
160                 ,cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator< tree_update_desc, ellen_bintree_hp::update_desc_pool_accessor > >
161             >::type
162         > set_type;
163
164         test<set_type, print_stat>();
165     }
166
167     void EllenBinTreeMapHdrTest::EllenBinTree_hp_less_pool_ic_stat()
168     {
169         typedef cc::EllenBinTreeMap< gc_type, key_type, value_type,
170             cc::ellen_bintree::make_map_traits<
171                 co::less< less >
172                 ,co::node_allocator< cds::memory::pool_allocator< tree_internal_node, ellen_bintree_hp::internal_node_pool_accessor > >
173                 ,cc::ellen_bintree::update_desc_allocator< cds::memory::pool_allocator< tree_update_desc, ellen_bintree_hp::update_desc_pool_accessor > >
174                 ,co::item_counter< cds::atomicity::item_counter >
175                 ,co::stat< cc::ellen_bintree::stat<> >
176             >::type
177         > set_type;
178
179         test<set_type, print_stat>();
180     }
181
182 } // namespace tree