2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H
32 #define CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H
34 #include "test_intrusive_feldman_hashset.h"
38 class intrusive_feldman_hashset_hp: public intrusive_feldman_hashset
40 typedef intrusive_feldman_hashset base_class;
47 // Precondition: set is empty
48 // Postcondition: set is empty
50 base_class::test( s );
52 ASSERT_TRUE( s.empty());
53 ASSERT_CONTAINER_SIZE( s, 0 );
55 typedef typename Set::value_type value_type;
56 size_t const nSetSize = std::max( s.head_size() * 2, static_cast<size_t>( 100 ));
58 std::vector< value_type > data;
59 std::vector< size_t> indices;
60 data.reserve( nSetSize );
61 indices.reserve( nSetSize );
62 for ( size_t key = 0; key < nSetSize; ++key ) {
63 data.push_back( value_type( static_cast<int>(key)));
64 indices.push_back( key );
66 shuffle( indices.begin(), indices.end());
68 typename Set::guarded_ptr gp;
70 // get/extract from empty set
71 for ( auto idx : indices ) {
77 gp = s.extract( i.key());
82 for ( auto& i : data ) {
84 ASSERT_TRUE( s.insert( i ));
88 for ( auto idx : indices ) {
91 EXPECT_EQ( i.nFindCount, 0u );
95 EXPECT_EQ( i.nFindCount, 1u );
97 gp = s.extract( i.key());
100 EXPECT_EQ( i.nEraseCount, 1u );
102 gp = s.extract( i.key());
105 gp = s.get( i.key());
110 ASSERT_TRUE( s.empty());
111 ASSERT_CONTAINER_SIZE( s, 0 );
113 // Force retiring cycle
114 Set::gc::force_dispose();
115 for ( auto& i : data ) {
116 EXPECT_EQ( i.nDisposeCount, 1u );
119 // erase_at( iterator )
120 for ( auto& i : data ) {
122 ASSERT_TRUE( s.insert( i ));
124 ASSERT_FALSE( s.empty());
125 ASSERT_CONTAINER_SIZE( s, nSetSize );
127 for ( auto it = s.begin(); it != s.end(); ++it ) {
128 ASSERT_TRUE( s.erase_at( it ));
129 ASSERT_FALSE( s.erase_at( it ));
131 ASSERT_TRUE( s.empty());
132 ASSERT_CONTAINER_SIZE( s, 0 );
134 // Force retiring cycle
135 Set::gc::force_dispose();
136 for ( auto& i : data ) {
137 EXPECT_EQ( i.nDisposeCount, 1u );
140 // erase_at( reverse_iterator )
141 for ( auto& i : data ) {
143 ASSERT_TRUE( s.insert( i ));
145 ASSERT_FALSE( s.empty());
146 ASSERT_CONTAINER_SIZE( s, nSetSize );
148 for ( auto it = s.rbegin(); it != s.rend(); ++it ) {
149 ASSERT_TRUE( s.erase_at( it ));
150 ASSERT_FALSE( s.erase_at( it ));
152 ASSERT_TRUE( s.empty());
153 ASSERT_CONTAINER_SIZE( s, 0 );
155 // Force retiring cycle
156 Set::gc::force_dispose();
157 for ( auto& i : data ) {
158 EXPECT_EQ( i.nDisposeCount, 1u );
163 } // namespace cds_test
165 #endif // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_FELDMAN_HASHSET_HP_H