From: khizmax Date: Sun, 2 Nov 2014 14:51:40 +0000 (+0300) Subject: Unit tests for set are only with C++11 std::set and std::unordered_set X-Git-Tag: v2.0.0~142 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=5b1423b260fb92f38ad7c15d90bc3e84859f95bd;p=libcds.git Unit tests for set are only with C++11 std::set and std::unordered_set --- diff --git a/projects/Win/vc12/cds.sln b/projects/Win/vc12/cds.sln index 8789bdbb..7bead727 100644 --- a/projects/Win/vc12/cds.sln +++ b/projects/Win/vc12/cds.sln @@ -79,8 +79,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "set", "set", "{A64449B7-90F ..\..\..\tests\unit\set2\set_defs.h = ..\..\..\tests\unit\set2\set_defs.h ..\..\..\tests\unit\set2\set_types.h = ..\..\..\tests\unit\set2\set_types.h ..\..\..\tests\unit\set2\std_hash_set.h = ..\..\..\tests\unit\set2\std_hash_set.h - ..\..\..\tests\unit\set2\std_hash_set_std.h = ..\..\..\tests\unit\set2\std_hash_set_std.h - ..\..\..\tests\unit\set2\std_hash_set_vc9.h = ..\..\..\tests\unit\set2\std_hash_set_vc9.h ..\..\..\tests\unit\set2\std_set.h = ..\..\..\tests\unit\set2\std_set.h EndProjectSection EndProject diff --git a/tests/unit/set2/std_hash_set.h b/tests/unit/set2/std_hash_set.h new file mode 100644 index 00000000..dcc6c422 --- /dev/null +++ b/tests/unit/set2/std_hash_set.h @@ -0,0 +1,102 @@ +//$$CDS-header$$ + +#ifndef __CDSUNIT_STD_HASH_SET_STD_H +#define __CDSUNIT_STD_HASH_SET_STD_H + +#include +#include //unique_lock + +namespace set2 { + + template ::other + > + class StdHashSet + : public std::unordered_set< + Value + , Hash + , EqualTo + , Alloc + > + { + public: + Lock m_lock; + typedef std::unique_lock scoped_lock; + typedef std::unordered_set< + Value + , Hash + , EqualTo + , Alloc + > base_class; + public: + typedef typename base_class::value_type value_type; + + StdHashSet( size_t nSetSize, size_t nLoadFactor ) + {} + + template + bool find( const Key& key ) + { + scoped_lock al( m_lock ); + return base_class::find( value_type(key) ) != base_class::end(); + } + + template + bool insert( Key const& key ) + { + scoped_lock al( m_lock ); + std::pair pRet = base_class::insert( value_type( key )); + return pRet.second; + } + + template + bool insert( Key const& key, Func func ) + { + scoped_lock al( m_lock ); + std::pair pRet = base_class::insert( value_type( key )); + if ( pRet.second ) { + func( *pRet.first ); + return true; + } + return false; + } + + template + std::pair ensure( const T& key, Func func ) + { + scoped_lock al( m_lock ); + std::pair pRet = base_class::insert( value_type( key )); + if ( pRet.second ) { + func( true, *pRet.first, key ); + return std::make_pair( true, true ); + } + else { + func( false, *pRet.first, key ); + return std::make_pair( true, false ); + } + } + + template + bool erase( const Key& key ) + { + scoped_lock al( m_lock ); + return base_class::erase( value_type(key) ) != 0; + } + + template + bool erase( const T& key, Func func ) + { + scoped_lock al( m_lock ); + typename base_class::iterator it = base_class::find( value_type(key) ); + if ( it != base_class::end() ) { + func( *it ); + return base_class::erase( it ) != base_class::end(); + } + return false; + } + + std::ostream& dump( std::ostream& stm ) { return stm; } + }; +} // namespace set2 + +#endif // #ifndef __CDSUNIT_STD_HASH_SET_STD_H diff --git a/tests/unit/set2/std_hash_set_std.h b/tests/unit/set2/std_hash_set_std.h deleted file mode 100644 index 611e76b0..00000000 --- a/tests/unit/set2/std_hash_set_std.h +++ /dev/null @@ -1,103 +0,0 @@ -//$$CDS-header$$ - -#ifndef __CDSUNIT_STD_HASH_SET_STD_H -#define __CDSUNIT_STD_HASH_SET_STD_H - -#include -#include // ref -#include //unique_lock - -namespace set2 { - - template ::other - > - class StdHashSet - : public std::unordered_set< - Value - , Hash - , EqualTo - , Alloc - > - { - public: - Lock m_lock; - typedef std::unique_lock scoped_lock; - typedef std::unordered_set< - Value - , Hash - , EqualTo - , Alloc - > base_class; - public: - typedef typename base_class::value_type value_type; - - StdHashSet( size_t nSetSize, size_t nLoadFactor ) - {} - - template - bool find( const Key& key ) - { - scoped_lock al( m_lock ); - return base_class::find( value_type(key) ) != base_class::end(); - } - - template - bool insert( Key const& key ) - { - scoped_lock al( m_lock ); - std::pair pRet = base_class::insert( value_type( key )); - return pRet.second; - } - - template - bool insert( Key const& key, Func func ) - { - scoped_lock al( m_lock ); - std::pair pRet = base_class::insert( value_type( key )); - if ( pRet.second ) { - func( *pRet.first ); - return true; - } - return false; - } - - template - std::pair ensure( const T& key, Func func ) - { - scoped_lock al( m_lock ); - std::pair pRet = base_class::insert( value_type( key )); - if ( pRet.second ) { - func( true, *pRet.first, key ); - return std::make_pair( true, true ); - } - else { - func( false, *pRet.first, key ); - return std::make_pair( true, false ); - } - } - - template - bool erase( const Key& key ) - { - scoped_lock al( m_lock ); - return base_class::erase( value_type(key) ) != 0; - } - - template - bool erase( const T& key, Func func ) - { - scoped_lock al( m_lock ); - typename base_class::iterator it = base_class::find( value_type(key) ); - if ( it != base_class::end() ) { - func( *it ); - return base_class::erase( it ) != base_class::end(); - } - return false; - } - - std::ostream& dump( std::ostream& stm ) { return stm; } - }; -} // namespace set2 - -#endif // #ifndef __CDSUNIT_STD_HASH_SET_STD_H diff --git a/tests/unit/set2/std_set.h b/tests/unit/set2/std_set.h index fa9a270d..096b121f 100644 --- a/tests/unit/set2/std_set.h +++ b/tests/unit/set2/std_set.h @@ -4,7 +4,6 @@ #define __CDSUNIT_STD_SET_VC_H #include -#include // ref #include //unique_lock namespace set2 { @@ -14,7 +13,7 @@ namespace set2 { class StdSet: public std::set { Lock m_lock; - typedef std::unique_lock AutoLock; + typedef std::unique_lock scoped_lock; typedef std::set base_class; public: typedef typename base_class::key_type value_type; @@ -26,20 +25,20 @@ namespace set2 { bool find( const Key& key ) { value_type v( key ); - AutoLock al( m_lock ); + scoped_lock al( m_lock ); return base_class::find( v ) != base_class::end(); } bool insert( value_type const& v ) { - AutoLock al( m_lock ); + scoped_lock al( m_lock ); return base_class::insert( v ).second; } template bool insert( Key const& key, Func func ) { - AutoLock al( m_lock ); + scoped_lock al( m_lock ); std::pair pRet = base_class::insert( value_type( key )); if ( pRet.second ) { func( *pRet.first ); @@ -51,7 +50,7 @@ namespace set2 { template std::pair ensure( const T& key, Func func ) { - AutoLock al( m_lock ); + scoped_lock al( m_lock ); std::pair pRet = base_class::insert( value_type( key )); if ( pRet.second ) { func( true, *pRet.first, key ); @@ -66,14 +65,14 @@ namespace set2 { template bool erase( const Key& key ) { - AutoLock al( m_lock ); + scoped_lock al( m_lock ); return base_class::erase( value_type(key) ) != 0; } template bool erase( const T& key, Func func ) { - AutoLock al( m_lock ); + scoped_lock al( m_lock ); typename base_class::iterator it = base_class::find( value_type(key) ); if ( it != base_class::end() ) { func( *it );