Removed trailing spaces
[libcds.git] / test / unit / set / feldman_hashset_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 "test_feldman_hashset_hp.h"
32
33 #include <cds/container/feldman_hashset_hp.h>
34
35 namespace {
36     namespace cc = cds::container;
37     typedef cds::gc::HP gc_type;
38
39     class FeldmanHashSet_HP : public cds_test::feldman_hashset_hp
40     {
41     protected:
42         typedef cds_test::feldman_hashset_hp base_class;
43
44         void SetUp()
45         {
46             struct set_traits: public cc::feldman_hashset::traits
47             {
48                 typedef get_hash hash_accessor;
49             };
50             typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type;
51
52             // +1 - for guarded_ptr
53             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
54             cds::threading::Manager::attachThread();
55         }
56
57         void TearDown()
58         {
59             cds::threading::Manager::detachThread();
60             cds::gc::hp::GarbageCollector::Destruct( true );
61         }
62     };
63
64     TEST_F( FeldmanHashSet_HP, defaulted )
65     {
66         typedef cc::FeldmanHashSet< gc_type, int_item,
67             typename cc::feldman_hashset::make_traits<
68                 cc::feldman_hashset::hash_accessor< get_hash >
69             >::type
70         > set_type;
71
72         set_type s;
73         test( s );
74     }
75
76     TEST_F( FeldmanHashSet_HP, compare )
77     {
78         typedef cc::FeldmanHashSet< gc_type, int_item,
79             typename cc::feldman_hashset::make_traits<
80                 cc::feldman_hashset::hash_accessor< get_hash >
81                 ,cds::opt::compare< cmp >
82             >::type
83         > set_type;
84
85         set_type s( 4, 5 );
86         test( s );
87     }
88
89     TEST_F( FeldmanHashSet_HP, less )
90     {
91         typedef cc::FeldmanHashSet< gc_type, int_item,
92             typename cc::feldman_hashset::make_traits<
93                 cc::feldman_hashset::hash_accessor< get_hash >
94                 ,cds::opt::less< std::less<int> >
95             >::type
96         > set_type;
97
98         set_type s( 3, 2 );
99         test( s );
100     }
101
102     TEST_F( FeldmanHashSet_HP, cmpmix )
103     {
104         typedef cc::FeldmanHashSet< gc_type, int_item,
105             typename cc::feldman_hashset::make_traits<
106                 cc::feldman_hashset::hash_accessor< get_hash >
107                 , cds::opt::less< std::less<int> >
108                 ,cds::opt::compare< cmp >
109             >::type
110         > set_type;
111
112         set_type s( 4, 4 );
113         test( s );
114     }
115
116     TEST_F( FeldmanHashSet_HP, item_counting )
117     {
118         struct set_traits: public cc::feldman_hashset::traits
119         {
120             typedef get_hash hash_accessor;
121             typedef cmp compare;
122             typedef std::less<int> less;
123             typedef simple_item_counter item_counter;
124         };
125         typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type;
126
127         set_type s( 3, 3 );
128         test( s );
129     }
130
131     TEST_F( FeldmanHashSet_HP, backoff )
132     {
133         struct set_traits: public cc::feldman_hashset::traits
134         {
135             typedef get_hash hash_accessor;
136             typedef cmp compare;
137             typedef cds::atomicity::item_counter item_counter;
138             typedef cds::backoff::yield back_off;
139         };
140         typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type;
141
142         set_type s( 8, 2 );
143         test( s );
144     }
145
146     TEST_F( FeldmanHashSet_HP, stat )
147     {
148         struct set_traits: public cc::feldman_hashset::traits
149         {
150             typedef get_hash hash_accessor;
151             typedef cds::backoff::yield back_off;
152             typedef cc::feldman_hashset::stat<> stat;
153         };
154         typedef cc::FeldmanHashSet< gc_type, int_item, set_traits > set_type;
155
156         set_type s( 1, 1 );
157         test( s );
158     }
159
160 } // namespace