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