Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_michael_map_lazy_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 "map/hdr_map.h"
32 #include <cds/urcu/general_buffered.h>
33 #include <cds/container/lazy_kvlist_rcu.h>
34 #include <cds/container/michael_map_rcu.h>
35
36 namespace map {
37     namespace {
38         struct map_traits: public cc::michael_map::traits
39         {
40             typedef HashMapHdrTest::hash_int            hash;
41             typedef HashMapHdrTest::simple_item_counter item_counter;
42         };
43         typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_type;
44
45         struct RCU_GPB_cmp_traits: public cc::lazy_list::traits
46         {
47             typedef HashMapHdrTest::cmp   compare;
48         };
49
50         struct RCU_GPB_less_traits: public cc::lazy_list::traits
51         {
52             typedef HashMapHdrTest::less  less;
53         };
54
55         struct RCU_GPB_cmpmix_traits: public cc::lazy_list::traits
56         {
57             typedef HashMapHdrTest::cmp   compare;
58             typedef HashMapHdrTest::less  less;
59         };
60     }
61
62     void HashMapHdrTest::Lazy_RCU_GPB_cmp()
63     {
64         typedef cc::LazyKVList< rcu_type, int, HashMapHdrTest::value_type, RCU_GPB_cmp_traits > list;
65
66         // traits-based version
67         typedef cc::MichaelHashMap< rcu_type, list, map_traits > map;
68         test_rcu< map >();
69
70         // option-based version
71         typedef cc::MichaelHashMap< rcu_type, list,
72             cc::michael_map::make_traits<
73                 cc::opt::hash< hash_int >
74                 ,cc::opt::item_counter< simple_item_counter >
75             >::type
76         > opt_map;
77         test_rcu< opt_map >();
78     }
79
80     void HashMapHdrTest::Lazy_RCU_GPB_less()
81     {
82         typedef cc::LazyKVList< rcu_type, int, HashMapHdrTest::value_type, RCU_GPB_less_traits > list;
83
84         // traits-based version
85         typedef cc::MichaelHashMap< rcu_type, list, map_traits > map;
86         test_rcu< map >();
87
88         // option-based version
89         typedef cc::MichaelHashMap< rcu_type, list,
90             cc::michael_map::make_traits<
91                 cc::opt::hash< hash_int >
92                 ,cc::opt::item_counter< simple_item_counter >
93             >::type
94         > opt_map;
95         test_rcu< opt_map >();
96     }
97
98     void HashMapHdrTest::Lazy_RCU_GPB_cmpmix()
99     {
100         typedef cc::LazyKVList< rcu_type, int, HashMapHdrTest::value_type, RCU_GPB_cmpmix_traits > list;
101
102         // traits-based version
103         typedef cc::MichaelHashMap< rcu_type, list, map_traits > map;
104         test_rcu< map >();
105
106         // option-based version
107         typedef cc::MichaelHashMap< rcu_type, list,
108             cc::michael_map::make_traits<
109                 cc::opt::hash< hash_int >
110                 ,cc::opt::item_counter< simple_item_counter >
111             >::type
112         > opt_map;
113         test_rcu< opt_map >();
114     }
115
116
117 } // namespace map
118