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