Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_striped_hashset_boost_unordered_set.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 "set/hdr_striped_set.h"
32 #include <cds/container/striped_set/boost_unordered_set.h>
33 #include <cds/container/striped_set.h>
34 #include <cds/sync/spinlock.h>
35
36 namespace set {
37
38     namespace {
39         struct equal_item
40         {
41             template <typename T>
42             bool operator ()( T const& i1, T const& i2) const
43             {
44                 return i1.key() == i2.key();
45             }
46         };
47
48         typedef boost::unordered_set< StripedSetHdrTest::item, StripedSetHdrTest::hash_int, equal_item > set_t;
49
50         struct my_copy_policy {
51             typedef set_t::iterator iterator;
52
53             void operator()( set_t& set, iterator itWhat )
54             {
55                 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
56             }
57         };
58     }
59
60     void StripedSetHdrTest::Striped_boost_unordered_set()
61     {
62         CPPUNIT_MESSAGE( "cmp");
63         typedef cc::StripedSet< set_t
64             , co::hash< hash_int >
65             , co::compare< cmp<item> >
66             ,co::mutex_policy< cc::striped_set::striping<> >
67         >   set_cmp;
68         test_striped< set_cmp >();
69
70         CPPUNIT_MESSAGE( "less");
71         typedef cc::StripedSet< set_t
72             , co::hash< hash_int >
73             , co::less< less<item> >
74             ,co::mutex_policy< cc::striped_set::striping<> >
75         >   set_less;
76         test_striped< set_less >();
77
78         CPPUNIT_MESSAGE( "cmpmix");
79         typedef cc::StripedSet< set_t
80             , co::hash< hash_int >
81             , co::compare< cmp<item> >
82             , co::less< less<item> >
83             ,co::mutex_policy< cc::striped_set::striping<> >
84         >   set_cmpmix;
85         test_striped< set_cmpmix >();
86
87         // Spinlock as lock policy
88         CPPUNIT_MESSAGE( "spinlock");
89         typedef cc::StripedSet< set_t
90             , co::hash< hash_int >
91             , co::less< less<item> >
92             , co::mutex_policy< cc::striped_set::striping< cds::sync::spin> >
93         >   set_spin;
94         test_striped< set_spin >();
95
96         // Resizing policy
97         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
98         {
99             typedef cc::StripedSet< set_t
100                 , co::hash< hash_int >
101                 , co::less< less<item> >
102                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
103             >   set_less_resizing_lf;
104             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
105             test_striped_with( s );
106         }
107
108         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
109         typedef cc::StripedSet< set_t
110             , co::hash< hash_int >
111             , co::less< less<item> >
112             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
113         >   set_less_resizing_lf16;
114         test_striped< set_less_resizing_lf16 >();
115
116         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
117         {
118             typedef cc::StripedSet< set_t
119                 , co::hash< hash_int >
120                 , co::less< less<item> >
121                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
122             >   set_less_resizing_sbt;
123             set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>(1024));
124             test_striped_with(s);
125         }
126
127         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
128         typedef cc::StripedSet< set_t
129             , co::hash< hash_int >
130             , co::less< less<item> >
131             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
132         >   set_less_resizing_sbt16;
133         test_striped< set_less_resizing_sbt16 >();
134
135         // Copy policy
136         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
137         typedef cc::StripedSet< set_t
138             , co::hash< hash_int >
139             , co::compare< cmp<item> >
140             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
141             , co::copy_policy< cc::striped_set::copy_item >
142         >   set_copy_item;
143         test_striped< set_copy_item >();
144
145         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
146         typedef cc::StripedSet< set_t
147             , co::hash< hash_int >
148             , co::compare< cmp<item> >
149             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
150             , co::copy_policy< cc::striped_set::swap_item >
151         >   set_swap_item;
152         test_striped< set_swap_item >();
153
154         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
155         typedef cc::StripedSet< set_t
156             , co::hash< hash_int >
157             , co::compare< cmp<item> >
158             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
159             , co::copy_policy< cc::striped_set::move_item >
160         >   set_move_item;
161         test_striped< set_move_item >();
162
163         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
164         typedef cc::StripedSet< set_t
165             , co::hash< hash_int >
166             , co::compare< cmp<item> >
167             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
168             , co::copy_policy< my_copy_policy >
169         >   set_special_copy_item;
170         test_striped< set_special_copy_item >();
171     }
172
173 }   // namespace set