2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #ifndef CDSUNIT_SET_TYPE_H
32 #define CDSUNIT_SET_TYPE_H
34 #include <cds/urcu/general_instant.h>
35 #include <cds/urcu/general_buffered.h>
36 #include <cds/urcu/general_threaded.h>
37 #include <cds/urcu/signal_buffered.h>
38 #include <cds/urcu/signal_threaded.h>
40 #include <cds/opt/hash.h>
41 #include <cds/sync/spinlock.h>
43 #include <cds_test/stress_test.h>
44 #include "framework/michael_alloc.h"
47 namespace cc = cds::container;
48 namespace co = cds::opt;
50 typedef cds::urcu::gc< cds::urcu::general_instant<> > rcu_gpi;
51 typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_gpb;
52 typedef cds::urcu::gc< cds::urcu::general_threaded<> > rcu_gpt;
53 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
54 typedef cds::urcu::gc< cds::urcu::signal_buffered<> > rcu_shb;
55 typedef cds::urcu::gc< cds::urcu::signal_threaded<> > rcu_sht;
58 template <typename Key>
61 template <typename Key>
64 int operator ()(Key const& k1, Key const& k2) const
66 if ( less<Key>( k1, k2 ) )
68 return less<Key>( k2, k1 ) ? 1 : 0;
72 template <typename Key>
75 #define CDSUNIT_INT_COMPARE(t) template <> struct cmp<t> { int operator()( t k1, t k2 ){ return (int)(k1 - k2); } }
76 CDSUNIT_INT_COMPARE(char);
77 CDSUNIT_INT_COMPARE(unsigned char);
78 CDSUNIT_INT_COMPARE(int);
79 CDSUNIT_INT_COMPARE(unsigned int);
80 CDSUNIT_INT_COMPARE(long);
81 CDSUNIT_INT_COMPARE(unsigned long);
82 CDSUNIT_INT_COMPARE(long long);
83 CDSUNIT_INT_COMPARE(unsigned long long);
84 #undef CDSUNIT_INT_COMPARE
87 struct cmp<std::string>
89 int operator()(std::string const& s1, std::string const& s2)
91 return s1.compare( s2 );
93 int operator()(std::string const& s1, char const * s2)
95 return s1.compare( s2 );
97 int operator()(char const * s1, std::string const& s2)
99 return -s2.compare( s1 );
104 template <typename ImplSelector, typename Key, typename Value>
107 template <typename Key, typename Value>
110 typedef Key key_type;
111 typedef Value value_type;
117 /*explicit*/ key_val( key_type const& k ): key(k), val() {}
118 key_val( key_type const& k, value_type const& v ): key(k), val(v) {}
120 template <typename K>
121 explicit key_val( K const& k ): key(k) {}
123 template <typename K, typename T>
124 key_val( K const& k, T const& v ): key(k), val(v) {}
127 typedef set::hash<key_type> key_hash;
128 typedef set::less<key_type> key_less;
129 typedef set::cmp<key_type> key_compare;
132 bool operator()( key_val const& k1, key_val const& k2 ) const
134 return key_less()( k1.key, k2.key );
136 bool operator()( key_type const& k1, key_val const& k2 ) const
138 return key_less()( k1, k2.key );
140 bool operator()( key_val const& k1, key_type const& k2 ) const
142 return key_less()( k1.key, k2 );
147 int operator()( key_val const& k1, key_val const& k2 ) const
149 return key_compare()( k1.key, k2.key );
151 int operator()( key_type const& k1, key_val const& k2 ) const
153 return key_compare()( k1, k2.key );
155 int operator()( key_val const& k1, key_type const& k2 ) const
157 return key_compare()( k1.key, k2 );
162 bool operator()( key_val const& k1, key_val const& k2 ) const
164 return key_compare()( k1.key, k2.key ) == 0;
166 bool operator()( key_type const& k1, key_val const& k2 ) const
168 return key_compare()( k1, k2.key ) == 0;
170 bool operator()( key_val const& k1, key_type const& k2 ) const
172 return key_compare()( k1.key, k2 ) == 0;
177 struct hash: public key_hash
179 size_t operator()( key_val const& v ) const
181 return key_hash::operator()( v.key );
183 size_t operator()( key_type const& key ) const
185 return key_hash::operator()( key );
187 template <typename Q>
188 size_t operator()( Q const& k ) const
190 return key_hash::operator()( k );
194 struct hash2: public hash
196 size_t operator()( key_val const& k ) const
198 size_t h = hash::operator ()( k.key );
200 seed ^= h + 0x9e3779b9 + (seed << 6) + (seed >> 2);
203 size_t operator()( key_type const& k ) const
205 size_t h = hash::operator ()( k );
207 seed ^= h + 0x9e3779b9 + (seed << 6) + (seed >> 2);
210 template <typename Q>
211 size_t operator()( Q const& k ) const
213 return key_hash::operator()( k );
219 // *************************************************
221 // *************************************************
223 template <typename Set>
224 static inline void print_stat( cds_test::property_stream&, Set const& /*s*/ )
228 //*******************************************************
230 //*******************************************************
232 template <typename Set>
233 static inline void additional_check( Set& /*set*/ )
236 template <typename Set>
237 static inline void additional_cleanup( Set& /*set*/ )
240 //*******************************************************
241 // check_before_clear
242 //*******************************************************
244 template <typename Set>
245 static inline void check_before_clear( Set& /*s*/ )
251 #endif // ifndef CDSUNIT_SET_TYPE_H