/*
This file is a part of libcds - Concurrent Data Structures library
- (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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:
base_class::test( s );
- ASSERT_TRUE( s.empty() );
+ ASSERT_TRUE( s.empty());
ASSERT_CONTAINER_SIZE( s, 0 );
typedef typename Set::value_type value_type;
data.reserve( kSize );
indices.reserve( kSize );
for ( size_t key = 0; key < kSize; ++key ) {
- data.push_back( value_type( static_cast<int>(key) ) );
+ data.push_back( value_type( static_cast<int>(key)));
indices.push_back( key );
}
- shuffle( indices.begin(), indices.end() );
+ shuffle( indices.begin(), indices.end());
typename Set::guarded_ptr gp;
gp = s.get( i );
ASSERT_TRUE( !gp );
- gp = s.get( i.key() );
+ gp = s.get( i.key());
ASSERT_TRUE( !gp );
gp = s.get_with( other_item( i.key()), other_less());
ASSERT_TRUE( !gp );
// fill set
for ( auto& i : data ) {
i.nDisposeCount = 0;
- ASSERT_TRUE( s.insert( i ) );
+ ASSERT_TRUE( s.insert( i ));
}
// get/extract
for ( auto idx : indices ) {
auto& i = data[idx];
- EXPECT_EQ( i.nFindCount, 0 );
+ EXPECT_EQ( i.nFindCount, 0u );
gp = s.get( i );
ASSERT_FALSE( !gp );
++gp->nFindCount;
- EXPECT_EQ( i.nFindCount, 1 );
+ EXPECT_EQ( i.nFindCount, 1u );
- gp = s.get( i.key() );
+ gp = s.get( i.key());
ASSERT_FALSE( !gp );
++gp->nFindCount;
- EXPECT_EQ( i.nFindCount, 2 );
+ EXPECT_EQ( i.nFindCount, 2u );
gp = s.get_with( other_item( i.key()), other_less());
ASSERT_FALSE( !gp );
++gp->nFindCount;
- EXPECT_EQ( i.nFindCount, 3 );
+ EXPECT_EQ( i.nFindCount, 3u );
- EXPECT_EQ( i.nEraseCount, 0 );
+ EXPECT_EQ( i.nEraseCount, 0u );
switch ( i.key() % 3 ) {
case 0:
gp = s.extract( i.key());
gp = s.extract( i );
break;
case 2:
- gp = s.extract_with( other_item( i.key() ), other_less() );
+ gp = s.extract_with( other_item( i.key()), other_less());
break;
}
ASSERT_FALSE( !gp );
++gp->nEraseCount;
- EXPECT_EQ( i.nEraseCount, 1 );
+ EXPECT_EQ( i.nEraseCount, 1u );
gp = s.extract( i );
ASSERT_TRUE( !gp );
- gp = s.extract( i.key() );
+ gp = s.extract( i.key());
ASSERT_TRUE( !gp );
- gp = s.extract_with( other_item( i.key() ), other_less() );
+ gp = s.extract_with( other_item( i.key()), other_less());
ASSERT_TRUE( !gp );
}
gp.release();
- ASSERT_TRUE( s.empty() );
+ 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 );
+ EXPECT_EQ( i.nDisposeCount, 1u );
+ }
+
+ // erase_at() test
+ for ( auto& i : data ) {
+ i.nDisposeCount = 0;
+ ASSERT_TRUE( s.insert( i ));
}
+ for ( auto it = s.begin(); it != s.end(); ++it ) {
+ EXPECT_TRUE( s.erase_at( it ));
+ EXPECT_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, 1u );
+ }
}
};