+++ /dev/null
-/*
- This file is a part of libcds - Concurrent Data Structures library
-
- (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
-
- Source code repo: http://github.com/khizmax/libcds/
- Download: http://sourceforge.net/projects/libcds/files/
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef CDSUNIT_SET_TYPE_H
-#define CDSUNIT_SET_TYPE_H
-
-#include <cds/urcu/general_instant.h>
-#include <cds/urcu/general_buffered.h>
-#include <cds/urcu/general_threaded.h>
-#include <cds/urcu/signal_buffered.h>
-#include <cds/urcu/signal_threaded.h>
-
-#include <cds/opt/hash.h>
-#include <cds/sync/spinlock.h>
-#include <boost/functional/hash/hash.hpp>
-
-#include "cppunit/cppunit_mini.h"
-#include "lock/nolock.h"
-#include "michael_alloc.h"
-
-namespace set2 {
- namespace cc = cds::container;
- namespace co = cds::opt;
-
- typedef cds::urcu::gc< cds::urcu::general_instant<> > rcu_gpi;
- typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_gpb;
- typedef cds::urcu::gc< cds::urcu::general_threaded<> > rcu_gpt;
-#ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
- typedef cds::urcu::gc< cds::urcu::signal_buffered<> > rcu_shb;
- typedef cds::urcu::gc< cds::urcu::signal_threaded<> > rcu_sht;
-#endif
-
- template <typename Key>
- struct cmp {
- int operator ()(Key const& k1, Key const& k2) const
- {
- if ( std::less<Key>( k1, k2 ) )
- return -1;
- return std::less<Key>( k2, k1 ) ? 1 : 0;
- }
- };
-
-#define CDSUNIT_INT_COMPARE(t) template <> struct cmp<t> { int operator()( t k1, t k2 ){ return (int)(k1 - k2); } }
- CDSUNIT_INT_COMPARE(char);
- CDSUNIT_INT_COMPARE(unsigned char);
- CDSUNIT_INT_COMPARE(int);
- CDSUNIT_INT_COMPARE(unsigned int);
- CDSUNIT_INT_COMPARE(long);
- CDSUNIT_INT_COMPARE(unsigned long);
- CDSUNIT_INT_COMPARE(long long);
- CDSUNIT_INT_COMPARE(unsigned long long);
-#undef CDSUNIT_INT_COMPARE
-
- template <>
- struct cmp<std::string>
- {
- int operator()(std::string const& s1, std::string const& s2)
- {
- return s1.compare( s2 );
- }
- int operator()(std::string const& s1, char const * s2)
- {
- return s1.compare( s2 );
- }
- int operator()(char const * s1, std::string const& s2)
- {
- return -s2.compare( s1 );
- }
- };
-
- // forward
- template <typename ImplSelector, typename Key, typename Value>
- struct set_type;
-
- template <typename Key, typename Value>
- struct set_type_base
- {
- typedef Key key_type;
- typedef Value value_type;
-
- struct key_val {
- key_type key;
- value_type val;
-
- /*explicit*/ key_val( key_type const& k ): key(k), val() {}
- key_val( key_type const& k, value_type const& v ): key(k), val(v) {}
-
- template <typename K>
- /*explicit*/ key_val( K const& k ): key(k) {}
-
- template <typename K, typename T>
- key_val( K const& k, T const& v ): key(k), val(v) {}
- };
-
- typedef co::v::hash<key_type> key_hash;
- typedef std::less<key_type> key_less;
- typedef cmp<key_type> key_compare;
-
- struct less {
- bool operator()( key_val const& k1, key_val const& k2 ) const
- {
- return key_less()( k1.key, k2.key );
- }
- bool operator()( key_type const& k1, key_val const& k2 ) const
- {
- return key_less()( k1, k2.key );
- }
- bool operator()( key_val const& k1, key_type const& k2 ) const
- {
- return key_less()( k1.key, k2 );
- }
- };
-
- struct compare {
- int operator()( key_val const& k1, key_val const& k2 ) const
- {
- return key_compare()( k1.key, k2.key );
- }
- int operator()( key_type const& k1, key_val const& k2 ) const
- {
- return key_compare()( k1, k2.key );
- }
- int operator()( key_val const& k1, key_type const& k2 ) const
- {
- return key_compare()( k1.key, k2 );
- }
- };
-
- struct equal_to {
- bool operator()( key_val const& k1, key_val const& k2 ) const
- {
- return key_compare()( k1.key, k2.key ) == 0;
- }
- bool operator()( key_type const& k1, key_val const& k2 ) const
- {
- return key_compare()( k1, k2.key ) == 0;
- }
- bool operator()( key_val const& k1, key_type const& k2 ) const
- {
- return key_compare()( k1.key, k2 ) == 0;
- }
- };
-
-
- struct hash: public key_hash
- {
- size_t operator()( key_val const& v ) const
- {
- return key_hash::operator()( v.key );
- }
- size_t operator()( key_type const& key ) const
- {
- return key_hash::operator()( key );
- }
- template <typename Q>
- size_t operator()( Q const& k ) const
- {
- return key_hash::operator()( k );
- }
- };
-
- struct hash2: public hash
- {
- size_t operator()( key_val const& k ) const
- {
- size_t seed = ~hash::operator ()( k );
- boost::hash_combine( seed, k.key );
- return seed;
- }
- size_t operator()( key_type const& k ) const
- {
- size_t seed = ~hash::operator ()( k );
- boost::hash_combine( seed, k );
- return seed;
- }
- template <typename Q>
- size_t operator()( Q const& k ) const
- {
- return key_hash::operator()( k );
- }
- };
- };
-
-
- // *************************************************
- // print_stat
- // *************************************************
-
- template <typename Set>
- static inline void print_stat( Set const& /*s*/ )
- {}
-
-
- //*******************************************************
- // additional_check
- //*******************************************************
-
- template <typename Set>
- static inline void additional_check( Set& /*set*/ )
- {}
-
- template <typename Set>
- static inline void additional_cleanup( Set& /*set*/ )
- {}
-
- //*******************************************************
- // check_before_clear
- //*******************************************************
-
- template <typename Set>
- static inline void check_before_clear( Set& /*s*/ )
- {}
-
-} // namespace set2
-
-#endif // ifndef CDSUNIT_SET_TYPE_H