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_FELDMAN_HASHSET_HP_H
32 #define CDSUNIT_SET_TEST_FELDMAN_HASHSET_HP_H
34 #include "test_feldman_hashset.h"
38 class feldman_hashset_hp: public feldman_hashset
40 typedef feldman_hashset base_class;
43 template <typename Set>
46 // Precondition: set is empty
47 // Postcondition: set is empty
49 ASSERT_TRUE( s.empty());
50 ASSERT_CONTAINER_SIZE( s, 0 );
52 base_class::test( s );
54 typedef typename Set::value_type value_type;
56 size_t const nSetSize = kSize;
57 std::vector< value_type > data;
58 std::vector< size_t> indices;
59 data.reserve( kSize );
60 indices.reserve( kSize );
61 for ( size_t key = 0; key < kSize; ++key ) {
62 data.push_back( value_type( static_cast<int>(key)));
63 indices.push_back( key );
65 shuffle( indices.begin(), indices.end());
67 for ( auto& i : data ) {
68 ASSERT_TRUE( s.insert( i ));
70 ASSERT_FALSE( s.empty());
71 ASSERT_CONTAINER_SIZE( s, nSetSize );
74 for ( auto it = s.begin(); it != s.end(); ++it ) {
75 it->nFindCount = it->key() * 3;
79 for ( auto it = s.cbegin(); it != s.cend(); ++it ) {
80 EXPECT_EQ( it->nFindCount, static_cast<size_t>( it->key() * 3 ));
83 // reverse iterator set
84 for ( auto it = s.rbegin(); it != s.rend(); ++it ) {
85 it->nFindCount = it->key() * 2;
88 for ( auto it = s.crbegin(); it != s.crend(); ++it ) {
89 EXPECT_EQ( it->nFindCount, static_cast<size_t>( it->key() * 2 ));
92 typedef typename Set::guarded_ptr guarded_ptr;
96 for ( auto idx : indices ) {
101 gp = s.get( i.key());
103 EXPECT_EQ( gp->key(), i.key());
104 EXPECT_EQ( gp->nFindCount, static_cast<size_t>( i.key() * 2 ));
111 for ( auto idx : indices ) {
115 gp = s.extract( i.key());
117 EXPECT_EQ( gp->key(), i.key());
118 EXPECT_EQ( gp->nFindCount, static_cast<size_t>( i.key() * 4 ));
120 gp = s.extract( i.key());
124 ASSERT_TRUE( s.empty());
125 ASSERT_CONTAINER_SIZE( s, 0 );
128 for ( auto& i : data ) {
129 ASSERT_TRUE( s.insert( i ));
131 ASSERT_FALSE( s.empty());
132 ASSERT_CONTAINER_SIZE( s, nSetSize );
134 for ( auto it = s.begin(); it != s.end(); ++it ) {
136 ASSERT_TRUE( s.erase_at( it ));
137 EXPECT_EQ( it->key(), key );
138 ASSERT_FALSE( s.erase_at( it ));
141 ASSERT_TRUE( s.empty());
142 ASSERT_CONTAINER_SIZE( s, 0 );
146 } // namespace cds_test
148 #endif // CDSUNIT_SET_TEST_FELDMAN_HASHSET_HP_H