Added internal statistics to MichaelSet/Map
[libcds.git] / test / unit / intrusive-set / intrusive_michael_iterable_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 "test_intrusive_michael_iterable_hp.h"
32
33 #include <cds/intrusive/iterable_list_dhp.h>
34 #include <cds/intrusive/michael_set.h>
35
36 namespace {
37     namespace ci = cds::intrusive;
38     typedef cds::gc::DHP gc_type;
39
40     class IntrusiveMichaelIterableSet_DHP : public cds_test::intrusive_set_hp
41     {
42     protected:
43         typedef cds_test::intrusive_set_hp base_class;
44
45     protected:
46         void SetUp()
47         {
48             struct list_traits : public ci::iterable_list::traits
49             {};
50             typedef ci::IterableList< gc_type, item_type, list_traits > list_type;
51             typedef ci::MichaelHashSet< gc_type, list_type > set_type;
52
53             cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
54             cds::threading::Manager::attachThread();
55         }
56
57         void TearDown()
58         {
59             cds::threading::Manager::detachThread();
60             cds::gc::dhp::GarbageCollector::Destruct();
61         }
62     };
63
64
65     TEST_F( IntrusiveMichaelIterableSet_DHP, cmp )
66     {
67         typedef ci::IterableList< gc_type
68             , item_type
69             ,ci::iterable_list::make_traits<
70                 ci::opt::compare< cmp<item_type> >
71                 ,ci::opt::disposer< mock_disposer >
72             >::type
73         > bucket_type;
74
75         typedef ci::MichaelHashSet< gc_type, bucket_type,
76             ci::michael_set::make_traits<
77                 ci::opt::hash< hash_int >
78             >::type
79         > set_type;
80
81         set_type s( kSize, 2 );
82         test( s );
83     }
84
85     TEST_F( IntrusiveMichaelIterableSet_DHP, less )
86     {
87         typedef ci::IterableList< gc_type
88             , item_type
89             ,ci::iterable_list::make_traits<
90                 ci::opt::less< less<item_type> >
91                 ,ci::opt::disposer< mock_disposer >
92             >::type
93         > bucket_type;
94
95         typedef ci::MichaelHashSet< gc_type, bucket_type,
96             ci::michael_set::make_traits<
97                 ci::opt::hash< hash_int >
98             >::type
99         > set_type;
100
101         set_type s( kSize, 2 );
102         test( s );
103     }
104
105     TEST_F( IntrusiveMichaelIterableSet_DHP, cmpmix )
106     {
107         struct list_traits : public ci::iterable_list::traits
108         {
109             typedef base_class::less<item_type> less;
110             typedef cmp<item_type> compare;
111             typedef mock_disposer disposer;
112         };
113         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
114
115         struct set_traits : public ci::michael_set::traits
116         {
117             typedef hash_int hash;
118             typedef simple_item_counter item_counter;
119         };
120         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
121
122         set_type s( kSize, 2 );
123         test( s );
124     }
125
126     TEST_F( IntrusiveMichaelIterableSet_DHP, stat )
127     {
128         struct list_traits: public ci::iterable_list::traits
129         {
130             typedef base_class::less<item_type> less;
131             typedef mock_disposer disposer;
132             typedef ci::iterable_list::stat<> stat;
133         };
134         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
135
136         struct set_traits: public ci::michael_set::traits
137         {
138             typedef hash_int hash;
139             typedef simple_item_counter item_counter;
140         };
141         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
142
143         set_type s( kSize, 2 );
144         test( s );
145         EXPECT_GE( s.statistics().m_nInsertSuccess, 0 );
146     }
147
148     TEST_F( IntrusiveMichaelIterableSet_DHP, wrapped_stat )
149     {
150         struct list_traits: public ci::iterable_list::traits
151         {
152             typedef base_class::less<item_type> less;
153             typedef mock_disposer disposer;
154             typedef ci::iterable_list::wrapped_stat<> stat;
155         };
156         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
157
158         struct set_traits: public ci::michael_set::traits
159         {
160             typedef hash_int hash;
161             typedef simple_item_counter item_counter;
162         };
163         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
164
165         set_type s( kSize, 2 );
166         test( s );
167         EXPECT_GE( s.statistics().m_nInsertSuccess, 0 );
168     }
169
170 } // namespace