Fixed container::StripedSet::emplace() bug
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_list.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_list.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::list<StripedSetHdrTest::item> list_type;
41             typedef list_type::iterator iterator;
42
43             void operator()( list_type& list, iterator itInsert, iterator itWhat )
44             {
45                 list.insert( itInsert, std::make_pair(itWhat->key(), itWhat->val()) );
46             }
47         };
48
49         typedef std::list<StripedSetHdrTest::item> sequence_t;
50     }
51
52     void StripedSetHdrTest::Refinable_list()
53     {
54         CPPUNIT_MESSAGE( "cmp");
55         typedef cc::StripedSet< sequence_t
56             ,co::mutex_policy< cc::striped_set::refinable<> >
57             , co::hash< hash_int >
58             , co::compare< cmp<item> >
59         >   set_cmp;
60         test_striped2< set_cmp >();
61
62         CPPUNIT_MESSAGE( "less");
63         typedef cc::StripedSet< sequence_t
64             ,co::mutex_policy< cc::striped_set::refinable<> >
65             , co::hash< hash_int >
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::mutex_policy< cc::striped_set::refinable<> >
73             , co::hash< hash_int >
74             , co::compare< cmp<item> >
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::mutex_policy< cc::striped_set::refinable<cds::sync::reentrant_spin> >
83             , co::hash< hash_int >
84             , co::less< less<item> >
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::mutex_policy< cc::striped_set::refinable<> >
93                 , co::hash< hash_int >
94                 , co::less< less<item> >
95                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
96             >   set_less_resizing_lf;
97             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(8));
98             test_striped_with(s);
99         }
100
101         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
102         typedef cc::StripedSet< sequence_t
103             ,co::mutex_policy< cc::striped_set::refinable<> >
104             , co::hash< hash_int >
105             , co::less< less<item> >
106             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
107         >   set_less_resizing_lf16;
108         test_striped2< set_less_resizing_lf16 >();
109
110         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
111         {
112             typedef cc::StripedSet< sequence_t
113                 ,co::mutex_policy< cc::striped_set::refinable<> >
114                 , co::hash< hash_int >
115                 , co::less< less<item> >
116                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
117             >   set_less_resizing_sbt;
118             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(8));
119             test_striped_with(s);
120         }
121
122         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
123         typedef cc::StripedSet< sequence_t
124             ,co::mutex_policy< cc::striped_set::refinable<> >
125             , co::hash< hash_int >
126             , co::less< less<item> >
127             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
128         >   set_less_resizing_sbt16;
129         test_striped2< set_less_resizing_sbt16 >();
130
131
132         // Copy policy
133         CPPUNIT_MESSAGE( "copy_item");
134         typedef cc::StripedSet< sequence_t
135             ,co::mutex_policy< cc::striped_set::refinable<> >
136             , co::hash< hash_int >
137             , co::compare< cmp<item> >
138             , co::copy_policy< cc::striped_set::copy_item >
139         >   set_copy_item;
140         test_striped2< set_copy_item >();
141
142         CPPUNIT_MESSAGE( "swap_item");
143         typedef cc::StripedSet< sequence_t
144             ,co::mutex_policy< cc::striped_set::refinable<> >
145             , co::hash< hash_int >
146             , co::compare< cmp<item> >
147             , co::copy_policy< cc::striped_set::swap_item >
148         >   set_swap_item;
149         test_striped2< set_swap_item >();
150
151         CPPUNIT_MESSAGE( "move_item");
152         typedef cc::StripedSet< sequence_t
153             ,co::mutex_policy< cc::striped_set::refinable<> >
154             , co::hash< hash_int >
155             , co::compare< cmp<item> >
156             , co::copy_policy< cc::striped_set::move_item >
157         >   set_move_item;
158         test_striped2< set_move_item >();
159
160         CPPUNIT_MESSAGE( "special copy policy");
161         typedef cc::StripedSet< sequence_t
162             ,co::mutex_policy< cc::striped_set::refinable<> >
163             , co::hash< hash_int >
164             , co::compare< cmp<item> >
165             , co::copy_policy< my_copy_policy >
166         >   set_special_copy_item;
167         test_striped2< set_special_copy_item >();
168     }
169
170 }   // namespace set