</ItemGroup>\r
<ItemGroup>\r
<ClCompile Include="..\..\..\test\unit\main.cpp" />\r
+ <ClCompile Include="..\..\..\test\unit\set\intrusive_feldman_hashset_dhp.cpp" />\r
+ <ClCompile Include="..\..\..\test\unit\set\intrusive_feldman_hashset_hp.cpp" />\r
<ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_dhp.cpp" />\r
<ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_hp.cpp" />\r
<ClCompile Include="..\..\..\test\unit\set\intrusive_michael_lazy_nogc.cpp" />\r
<ClCompile Include="..\..\..\test\unit\set\intrusive_split_michael_rcu_sht.cpp" />\r
</ItemGroup>\r
<ItemGroup>\r
+ <ClInclude Include="..\..\..\test\unit\set\test_intrusive_feldman_hashset.h" />\r
+ <ClInclude Include="..\..\..\test\unit\set\test_intrusive_feldman_hashset_hp.h" />\r
<ClInclude Include="..\..\..\test\unit\set\test_intrusive_michael_lazy_rcu.h" />\r
<ClInclude Include="..\..\..\test\unit\set\test_intrusive_michael_michael_rcu.h" />\r
<ClInclude Include="..\..\..\test\unit\set\test_intrusive_set.h" />\r
<Filter Include="Source Files\intrusive::SkipList">\r
<UniqueIdentifier>{9c07e86e-bd5b-4ae1-a730-c768234ba9f0}</UniqueIdentifier>\r
</Filter>\r
+ <Filter Include="Source Files\intrusive:FeldmanHashSet">\r
+ <UniqueIdentifier>{852d2603-551b-460b-b17f-f370d91f79e7}</UniqueIdentifier>\r
+ </Filter>\r
</ItemGroup>\r
<ItemGroup>\r
<ClCompile Include="..\..\..\test\unit\main.cpp">\r
<ClCompile Include="..\..\..\test\unit\set\intrusive_skiplist_nogc.cpp">\r
<Filter>Source Files\intrusive::SkipList</Filter>\r
</ClCompile>\r
+ <ClCompile Include="..\..\..\test\unit\set\intrusive_feldman_hashset_hp.cpp">\r
+ <Filter>Source Files\intrusive:FeldmanHashSet</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="..\..\..\test\unit\set\intrusive_feldman_hashset_dhp.cpp">\r
+ <Filter>Source Files\intrusive:FeldmanHashSet</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="..\..\..\test\unit\set\test_intrusive_set.h">\r
<ClInclude Include="..\..\..\test\unit\set\test_intrusive_skiplist_rcu.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="..\..\..\test\unit\set\test_intrusive_feldman_hashset.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\test\unit\set\test_intrusive_feldman_hashset_hp.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file
set(CDSGTEST_SET_SOURCES
../main.cpp
+ intrusive_feldman_hashset_hp.cpp
+ intrusive_feldman_hashset_dhp.cpp
intrusive_michael_lazy_hp.cpp
intrusive_michael_lazy_dhp.cpp
intrusive_michael_lazy_nogc.cpp
--- /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.
+*/
+
+#include "test_intrusive_feldman_hashset_hp.h"
+
+#include <cds/intrusive/feldman_hashset_dhp.h>
+
+namespace {
+ namespace ci = cds::intrusive;
+ typedef cds::gc::DHP gc_type;
+
+ class IntrusiveFeldmanHashSet_DHP : public cds_test::intrusive_feldman_hashset_hp
+ {
+ protected:
+ typedef cds_test::intrusive_feldman_hashset_hp base_class;
+
+ protected:
+
+ void SetUp()
+ {
+ typedef ci::FeldmanHashSet< gc_type, int_item,
+ typename ci::feldman_hashset::make_traits<
+ ci::feldman_hashset::hash_accessor< hash_accessor >
+ ,ci::opt::less< std::less<int>>
+ ,ci::opt::disposer<mock_disposer>
+ >::type
+ > set_type;
+
+ cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
+ cds::threading::Manager::attachThread();
+ }
+
+ void TearDown()
+ {
+ cds::threading::Manager::detachThread();
+ cds::gc::dhp::GarbageCollector::Destruct();
+ }
+ };
+
+ TEST_F( IntrusiveFeldmanHashSet_DHP, compare )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s;
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_DHP, less )
+ {
+ typedef ci::FeldmanHashSet< gc_type, int_item,
+ typename ci::feldman_hashset::make_traits<
+ ci::feldman_hashset::hash_accessor< hash_accessor >
+ , ci::opt::less< std::less<int>>
+ , ci::opt::disposer<mock_disposer>
+ >::type
+ > set_type;
+
+ set_type s( 5, 2 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_DHP, cmpmix )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef std::less<int> less;
+ typedef mock_disposer disposer;
+ typedef simple_item_counter item_counter;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 3, 4 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_DHP, backoff )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ typedef cds::backoff::empty back_off;
+ typedef ci::opt::v::sequential_consistent memory_model;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 8, 3 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_DHP, stat )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ typedef ci::feldman_hashset::stat<> stat;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 8, 3 );
+ test( s );
+ }
+
+} // namespace
--- /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.
+*/
+
+#include "test_intrusive_feldman_hashset_hp.h"
+
+#include <cds/intrusive/feldman_hashset_hp.h>
+
+namespace {
+ namespace ci = cds::intrusive;
+ typedef cds::gc::HP gc_type;
+
+ class IntrusiveFeldmanHashSet_HP : public cds_test::intrusive_feldman_hashset_hp
+ {
+ protected:
+ typedef cds_test::intrusive_feldman_hashset_hp base_class;
+
+ protected:
+
+ void SetUp()
+ {
+ typedef ci::FeldmanHashSet< gc_type, int_item,
+ typename ci::feldman_hashset::make_traits<
+ ci::feldman_hashset::hash_accessor< hash_accessor >
+ ,ci::opt::less< std::less<int>>
+ ,ci::opt::disposer<mock_disposer>
+ >::type
+ > set_type;
+
+ // +1 - for guarded_ptr
+ cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
+ cds::threading::Manager::attachThread();
+ }
+
+ void TearDown()
+ {
+ cds::threading::Manager::detachThread();
+ cds::gc::hp::GarbageCollector::Destruct( true );
+ }
+ };
+
+ TEST_F( IntrusiveFeldmanHashSet_HP, compare )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s;
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_HP, less )
+ {
+ typedef ci::FeldmanHashSet< gc_type, int_item,
+ typename ci::feldman_hashset::make_traits<
+ ci::feldman_hashset::hash_accessor< hash_accessor >
+ , ci::opt::less< std::less<int>>
+ , ci::opt::disposer<mock_disposer>
+ >::type
+ > set_type;
+
+ set_type s( 5, 2 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_HP, cmpmix )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef std::less<int> less;
+ typedef mock_disposer disposer;
+ typedef simple_item_counter item_counter;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 3, 4 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_HP, backoff )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ typedef cds::backoff::empty back_off;
+ typedef ci::opt::v::sequential_consistent memory_model;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 8, 3 );
+ test( s );
+ }
+
+ TEST_F( IntrusiveFeldmanHashSet_HP, stat )
+ {
+ struct traits : public ci::feldman_hashset::traits
+ {
+ typedef base_class::hash_accessor hash_accessor;
+ typedef cmp compare;
+ typedef mock_disposer disposer;
+ typedef ci::feldman_hashset::stat<> stat;
+ };
+
+ typedef ci::FeldmanHashSet< gc_type, int_item, traits > set_type;
+
+ set_type s( 8, 3 );
+ test( s );
+ }
+
+} // namespace
--- /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_TEST_INTRUSIVE_FELDMAN_HASHSET_H
+#define CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_H
+
+#include <cds_test/check_size.h>
+#include <cds_test/fixture.h>
+
+#include <cds/opt/hash.h>
+#include <functional> // ref
+
+// forward declaration
+namespace cds { namespace intrusive {}}
+
+namespace cds_test {
+
+ namespace ci = cds::intrusive;
+ namespace co = cds::opt;
+
+ class intrusive_feldman_hashset: public fixture
+ {
+ public:
+ struct stat
+ {
+ unsigned int nDisposeCount ; // count of disposer calling
+ unsigned int nFindCount ; // count of find-functor calling
+ unsigned int nInsertCount ;
+ mutable unsigned int nEraseCount;
+
+ stat()
+ {
+ clear_stat();
+ }
+
+ void clear_stat()
+ {
+ memset( this, 0, sizeof( *this ) );
+ }
+ };
+
+ struct int_item: public stat
+ {
+ int nKey;
+ int nVal;
+
+ int_item()
+ {}
+
+ explicit int_item( int key )
+ : nKey( key )
+ , nVal( key )
+ {}
+
+ int_item(int key, int val)
+ : nKey( key )
+ , nVal(val)
+ {}
+
+ int_item( int_item const& v )
+ : stat()
+ , nKey( v.nKey )
+ , nVal( v.nVal )
+ {}
+
+ int key() const
+ {
+ return nKey;
+ }
+ };
+
+ struct hash_accessor {
+ int operator()( int_item const& v ) const
+ {
+ return v.key();
+ }
+ };
+
+ struct simple_item_counter {
+ size_t m_nCount;
+
+ simple_item_counter()
+ : m_nCount(0)
+ {}
+
+ size_t operator ++()
+ {
+ return ++m_nCount;
+ }
+
+ size_t operator --()
+ {
+ return --m_nCount;
+ }
+
+ void reset()
+ {
+ m_nCount = 0;
+ }
+
+ operator size_t() const
+ {
+ return m_nCount;
+ }
+ };
+
+ struct cmp {
+ int operator ()( int lhs, int rhs ) const
+ {
+ if ( lhs < rhs )
+ return -1;
+ return lhs > rhs ? 1 : 0;
+ }
+ };
+
+ struct mock_disposer
+ {
+ template <typename T>
+ void operator ()( T * p )
+ {
+ ++p->nDisposeCount;
+ }
+ };
+
+ protected:
+ template <class Set>
+ void test( Set& s )
+ {
+ // Precondition: set is empty
+ // Postcondition: set is empty
+
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+ size_t const nSetSize = std::max( s.head_size() * 2, static_cast<size_t>(100) );
+
+ typedef typename Set::value_type value_type;
+
+ std::vector< value_type > data;
+ std::vector< size_t> indices;
+ data.reserve( nSetSize );
+ indices.reserve( nSetSize );
+ for ( size_t key = 0; key < nSetSize; ++key ) {
+ data.push_back( value_type( static_cast<int>( key )));
+ indices.push_back( key );
+ }
+ shuffle( indices.begin(), indices.end() );
+
+ // insert/find
+ for ( auto idx : indices ) {
+ auto& i = data[ idx ];
+
+ ASSERT_FALSE( s.contains( i.nKey ));
+ ASSERT_FALSE( s.find( i.nKey, []( value_type& ) {} ));
+
+ std::pair<bool, bool> updResult;
+
+ updResult = s.update( i, false );
+ EXPECT_FALSE( updResult.first );
+ EXPECT_FALSE( updResult.second );
+
+ switch ( i.key() % 3 ) {
+ case 0:
+ ASSERT_TRUE( s.insert( i ));
+ ASSERT_FALSE( s.insert( i ));
+ updResult = s.update( i, false );
+ EXPECT_TRUE( updResult.first );
+ EXPECT_FALSE( updResult.second );
+ break;
+ case 1:
+ EXPECT_EQ( i.nInsertCount, 0 );
+ ASSERT_TRUE( s.insert( i, []( value_type& v ) { ++v.nInsertCount;} ));
+ EXPECT_EQ( i.nInsertCount, 1 );
+ ASSERT_FALSE( s.insert( i, []( value_type& v ) { ++v.nInsertCount;} ) );
+ EXPECT_EQ( i.nInsertCount, 1 );
+ i.nInsertCount = 0;
+ break;
+ case 2:
+ updResult = s.update( i );
+ EXPECT_TRUE( updResult.first );
+ EXPECT_TRUE( updResult.second );
+ break;
+ }
+
+ ASSERT_TRUE( s.contains( i.nKey ) );
+ EXPECT_EQ( i.nFindCount, 0 );
+ ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) { ++v.nFindCount; } ));
+ EXPECT_EQ( i.nFindCount, 1 );
+ }
+ ASSERT_FALSE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, nSetSize );
+
+ std::for_each( data.begin(), data.end(), []( value_type& v ) { v.clear_stat(); });
+
+ // erase
+ shuffle( indices.begin(), indices.end() );
+ for ( auto idx : indices ) {
+ auto& i = data[ idx ];
+
+ ASSERT_TRUE( s.contains( i.nKey ) );
+ EXPECT_EQ( i.nFindCount, 0 );
+ ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) { ++v.nFindCount; } ) );
+ EXPECT_EQ( i.nFindCount, 1 );
+
+ value_type v( i );
+ switch ( i.key() % 3 ) {
+ case 0:
+ ASSERT_FALSE( s.unlink( v ));
+ ASSERT_TRUE( s.unlink( i ));
+ ASSERT_FALSE( s.unlink( i ) );
+ break;
+ case 1:
+ ASSERT_TRUE( s.erase( i.key()));
+ ASSERT_FALSE( s.erase( i.key() ) );
+ break;
+ case 2:
+ EXPECT_EQ( i.nEraseCount, 0 );
+ ASSERT_TRUE( s.erase( v.key(), []( value_type& val ) { ++val.nEraseCount; } ));
+ EXPECT_EQ( i.nEraseCount, 1 );
+ ASSERT_FALSE( s.erase( v.key(), []( value_type& val ) { ++val.nEraseCount; } ));
+ EXPECT_EQ( i.nEraseCount, 1 );
+ break;
+ }
+
+ ASSERT_FALSE( s.contains( i.nKey ));
+ ASSERT_FALSE( s.find( i.nKey, []( value_type const& ) {} ));
+ }
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+
+ // Force retiring cycle
+ Set::gc::force_dispose();
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nDisposeCount, 1 );
+ }
+
+ // erase_at( iterator )
+ for ( auto& i : data ) {
+ i.clear_stat();
+ ASSERT_TRUE( s.insert( i ) );
+ }
+ ASSERT_FALSE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, nSetSize );
+
+ for ( auto it = s.begin(); it != s.end(); ++it ) {
+ ASSERT_TRUE( s.erase_at( it ));
+ ASSERT_FALSE( s.erase_at( it ));
+ }
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+
+ // Force retiring cycle
+ Set::gc::force_dispose();
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nDisposeCount, 1 );
+ }
+
+ // erase_at( reverse_iterator )
+ for ( auto& i : data ) {
+ i.clear_stat();
+ ASSERT_TRUE( s.insert( i ) );
+ }
+ ASSERT_FALSE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, nSetSize );
+
+ for ( auto it = s.rbegin(); it != s.rend(); ++it ) {
+ ASSERT_TRUE( s.erase_at( it ) );
+ ASSERT_FALSE( s.erase_at( it ) );
+ }
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+
+ // Force retiring cycle
+ Set::gc::force_dispose();
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nDisposeCount, 1 );
+ }
+
+ // clear
+ for ( auto& i : data ) {
+ i.clear_stat();
+ ASSERT_TRUE( s.insert( i ));
+ }
+ ASSERT_FALSE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, nSetSize );
+
+ // Forward iterator test
+ for ( auto it = s.begin(); it != s.end(); ++it ) {
+ ++it->nFindCount;
+ }
+ for ( auto it = s.cbegin(); it != s.cend(); ++it ) {
+ EXPECT_EQ( it->nFindCount, 1 );
+ }
+
+ // Reverse iterator test
+ for ( auto it = s.rbegin(); it != s.rend(); ++it ) {
+ ++it->nFindCount;
+ }
+ for ( auto it = s.crbegin(); it != s.crend(); ++it ) {
+ EXPECT_EQ( it->nFindCount, 2 );
+ }
+
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nFindCount, 2 );
+ }
+
+ // clear test
+ s.clear();
+
+ ASSERT_TRUE( s.empty());
+ ASSERT_CONTAINER_SIZE( s, 0 );
+ ASSERT_TRUE( s.begin() == s.end() );
+ ASSERT_TRUE( s.cbegin() == s.cend() );
+
+ // Force retiring cycle
+ Set::gc::force_dispose();
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nDisposeCount, 1 );
+ }
+ }
+ };
+
+} // namespace cds_test
+
+#endif // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_H
--- /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_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H
+#define CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H
+
+#include "test_intrusive_feldman_hashset.h"
+
+// forward declaration
+namespace cds { namespace intrusive {}}
+
+namespace cds_test {
+
+ namespace ci = cds::intrusive;
+ namespace co = cds::opt;
+
+ class intrusive_feldman_hashset_hp: public intrusive_feldman_hashset
+ {
+ typedef intrusive_feldman_hashset base_class;
+
+ protected:
+
+ template <class Set>
+ void test( Set& s )
+ {
+ // Precondition: set is empty
+ // Postcondition: set is empty
+
+ base_class::test( s );
+
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+
+ typedef typename Set::value_type value_type;
+ size_t const nSetSize = std::max( s.head_size() * 2, static_cast<size_t>( 100 ));
+
+ std::vector< value_type > data;
+ std::vector< size_t> indices;
+ data.reserve( nSetSize );
+ indices.reserve( nSetSize );
+ for ( size_t key = 0; key < nSetSize; ++key ) {
+ data.push_back( value_type( static_cast<int>(key) ) );
+ indices.push_back( key );
+ }
+ shuffle( indices.begin(), indices.end() );
+
+ typename Set::guarded_ptr gp;
+
+ // get/extract from empty set
+ for ( auto idx : indices ) {
+ auto& i = data[idx];
+
+ gp = s.get( i.key() );
+ ASSERT_TRUE( !gp );
+
+ gp = s.extract( i.key());
+ ASSERT_TRUE( !gp );
+ }
+
+ // fill set
+ for ( auto& i : data ) {
+ i.nDisposeCount = 0;
+ ASSERT_TRUE( s.insert( i ) );
+ }
+
+ // get_level_statistics
+ {
+ std::vector< ci::feldman_hashset::level_statistics > level_stat;
+ s.get_level_statistics( level_stat );
+ EXPECT_GT( level_stat.size(), 0 );
+ }
+
+ // get/extract
+ for ( auto idx : indices ) {
+ auto& i = data[idx];
+
+ EXPECT_EQ( i.nFindCount, 0 );
+ gp = s.get( i.key() );
+ ASSERT_FALSE( !gp );
+ ++gp->nFindCount;
+ EXPECT_EQ( i.nFindCount, 1 );
+
+ gp = s.extract( i.key());
+ ASSERT_FALSE( !gp );
+ ++gp->nEraseCount;
+ EXPECT_EQ( i.nEraseCount, 1 );
+
+ gp = s.extract( i.key() );
+ ASSERT_TRUE( !gp );
+
+ gp = s.get( i.key() );
+ ASSERT_TRUE( !gp );
+ }
+ gp.release();
+
+ ASSERT_TRUE( s.empty() );
+ ASSERT_CONTAINER_SIZE( s, 0 );
+
+ // Force retiring cycle
+ Set::gc::force_dispose();
+ for ( auto& i : data ) {
+ EXPECT_EQ( i.nDisposeCount, 1 );
+ }
+
+ }
+ };
+
+} // namespace cds_test
+
+#endif // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H