3 #ifndef CDSTEST_HDR_SET_H
4 #define CDSTEST_HDR_SET_H
6 #include "cppunit/cppunit_proxy.h"
7 #include "size_check.h"
9 #include <cds/opt/hash.h>
10 #include <cds/os/timer.h>
11 #include <functional> // ref
12 #include <algorithm> // random_shuffle
14 // forward namespace declaration
16 namespace container {}
21 using misc::check_size;
23 namespace cc = cds::container;
24 namespace co = cds::opt;
27 class HashSetHdrTest: public CppUnitMini::TestCase
32 unsigned int nFindCount ; // count of find-functor calling
33 unsigned int nEnsureNewCount;
34 unsigned int nEnsureCount;
38 memset( this, 0, sizeof(*this));
41 void copy( stat const& s )
43 nFindCount = s.nFindCount;
44 nEnsureCount = s.nEnsureCount;
45 nEnsureNewCount = s.nEnsureNewCount;
49 struct item: public stat
62 item (int key, int val )
67 item( std::pair<int,int> const& p )
77 item& operator=(item const& i)
91 //item& operator=(item&& i)
110 size_t operator()( int i ) const
112 return co::v::hash<int>()( i );
115 size_t operator()( std::pair<int,int> const& i ) const
117 return co::v::hash<int>()( i.first );
120 template <typename Item>
121 size_t operator()( Item const& i ) const
123 return (*this)( i.key() );
127 struct simple_item_counter {
130 simple_item_counter()
149 operator size_t() const
155 template <typename T>
158 bool operator ()(const T& v1, const T& v2 ) const
160 return v1.key() < v2.key();
163 template <typename Q>
164 bool operator ()(const T& v1, const Q& v2 ) const
166 return v1.key() < v2;
169 template <typename Q>
170 bool operator ()(const Q& v1, const T& v2 ) const
172 return v1 < v2.key();
175 bool operator ()( std::pair<int, int> const& v1, const T& v2 ) const
177 return v1.first < v2.key();
180 bool operator ()(const T& v1, std::pair<int, int> const& v2 ) const
182 return v1.key() < v2.first;
189 other_item( int key )
201 template <typename T>
202 bool operator ()(T const& v1, other_item const& v2 ) const
204 return v1.key() < v2.nKey;
206 template <typename T>
207 bool operator ()(other_item const& v1, T const& v2 ) const
209 return v1.nKey < v2.key();
213 template <typename T>
215 int operator ()(const T& v1, const T& v2 ) const
217 if ( v1.key() < v2.key() )
219 return v1.key() > v2.key() ? 1 : 0;
222 template <typename Q>
223 int operator ()(const T& v1, const Q& v2 ) const
227 return v1.key() > v2 ? 1 : 0;
230 template <typename Q>
231 int operator ()(const Q& v1, const T& v2 ) const
235 return v1 > v2.key() ? 1 : 0;
238 int operator()( std::pair<int,int> const& v1, T const& v2 ) const
240 if ( v1.first < v2.key() )
242 return v1.first > v2.key() ? 1 : 0;
245 int operator()( T const& v1, std::pair<int,int> const& v2 ) const
247 if ( v1.key() < v2.first )
249 return v1.key() > v2.first ? 1 : 0;
253 template <typename T>
256 bool operator ()(const T& v1, const T& v2 ) const
258 return v1.key() == v2.key();
261 template <typename Q>
262 bool operator ()(const T& v1, const Q& v2 ) const
264 return v1.key() == v2;
267 template <typename Q>
268 bool operator ()(const Q& v1, const T& v2 ) const
270 return v1 == v2.key();
273 bool operator ()( std::pair<int, int> const& v1, const T& v2 ) const
275 return v1.first == v2.key();
278 bool operator ()(const T& v1, std::pair<int, int> const& v2 ) const
280 return v1.key() == v2.first;
286 template <typename Item, typename T>
287 void operator()( Item& i, T& /*val*/ ) const
291 template <typename Item, typename T>
292 void operator()( Item& i, T const& /*val*/ ) const
298 template <typename Item>
303 template <typename T>
304 void operator()( Item& i, T& /*val*/ )
309 void operator()( Item const& i )
315 struct insert_functor
317 template <typename Item>
318 void operator()(Item& i )
320 i.nVal = i.nKey * 100;
324 template <typename Item, typename Q>
325 static void ensure_func( bool bNew, Item& i, Q& /*val*/ )
333 struct ensure_functor
335 template <typename Item, typename Q>
336 void operator()( bool bNew, Item& i, Q& val )
338 ensure_func( bNew, i, val );
349 CPPUNIT_ASSERT( s.empty() );
351 const int nLimit = 100;
352 typename Set::guarded_ptr gp;
353 int arrRandom[nLimit];
354 for ( int i = 0; i < nLimit; ++i )
356 std::random_shuffle( arrRandom, arrRandom + nLimit );
358 for ( int i = 0; i < nLimit; ++i )
359 CPPUNIT_ASSERT( s.insert( arrRandom[i] ));
361 for ( int i = 0; i < nLimit; ++i ) {
362 int nKey = arrRandom[i];
364 CPPUNIT_ASSERT( gp );
365 CPPUNIT_ASSERT( !gp.empty());
366 CPPUNIT_CHECK( gp->nKey == nKey );
367 CPPUNIT_CHECK( gp->nVal == nKey );
370 gp = s.extract( nKey );
371 CPPUNIT_ASSERT( gp );
372 CPPUNIT_ASSERT( !gp.empty());
373 CPPUNIT_CHECK( gp->nKey == nKey );
374 CPPUNIT_CHECK( gp->nVal == nKey );
376 CPPUNIT_CHECK( !s.get( nKey ) );
378 gp = s.extract( nKey );
379 CPPUNIT_CHECK( !gp );
380 CPPUNIT_CHECK( gp.empty());
382 CPPUNIT_ASSERT( s.empty() );
385 for ( int i = 0; i < nLimit; ++i )
386 CPPUNIT_ASSERT( s.insert( arrRandom[i] ));
388 for ( int i = 0; i < nLimit; ++i ) {
389 int nKey = arrRandom[i];
390 gp = s.get_with( other_item( nKey ), other_less() );
391 CPPUNIT_ASSERT( gp );
392 CPPUNIT_ASSERT( !gp.empty());
393 CPPUNIT_CHECK( gp->nKey == nKey );
394 CPPUNIT_CHECK( gp->nVal == nKey );
397 gp = s.extract_with( other_item( nKey ), other_less() );
398 CPPUNIT_ASSERT( gp );
399 CPPUNIT_ASSERT( !gp.empty());
400 CPPUNIT_CHECK( gp->nKey == nKey );
401 CPPUNIT_CHECK( gp->nVal == nKey );
404 gp = s.get_with( other_item( nKey ), other_less() );
405 CPPUNIT_CHECK( !gp );
407 CPPUNIT_CHECK( !s.extract_with(other_item(nKey), other_less() ));
408 CPPUNIT_CHECK( gp.empty());
410 CPPUNIT_ASSERT( s.empty() );
425 typedef typename Set::gc rcu;
426 typedef typename Set::rcu_lock rcu_lock;
427 typedef typename Set::value_type value_type;
428 typename Set::exempt_ptr ep;
430 static size_t const nLimit = 100;
432 for ( size_t i = 0; i < nLimit; ++i )
434 std::random_shuffle( arr, arr + nLimit );
436 for ( size_t i = 0; i < nLimit; ++i )
437 CPPUNIT_ASSERT( s.insert( arr[i] ));
439 for ( size_t i = 0; i < nLimit; i += 2 ) {
444 pVal = s.get( nKey );
445 CPPUNIT_ASSERT( pVal != nullptr );
446 CPPUNIT_CHECK( pVal->nKey == nKey );
447 CPPUNIT_CHECK( pVal->nVal == nKey );
449 ep = s.extract( nKey );
450 CPPUNIT_ASSERT( ep );
451 CPPUNIT_ASSERT( !ep.empty() );
452 CPPUNIT_CHECK( pVal->nKey == ep->nKey );
453 CPPUNIT_CHECK( pVal->nVal == (*ep).nVal );
458 CPPUNIT_CHECK( s.get( nKey ) == nullptr );
459 ep = s.extract( nKey );
460 CPPUNIT_CHECK( !ep );
461 CPPUNIT_CHECK( ep.empty() );
464 pVal = s.get_with( other_item(nKey), other_less() );
465 CPPUNIT_ASSERT( pVal != nullptr );
466 CPPUNIT_CHECK( pVal->nKey == nKey );
467 CPPUNIT_CHECK( pVal->nVal == nKey );
469 ep = s.extract_with( other_item( nKey ), other_less() );
470 CPPUNIT_ASSERT( ep );
471 CPPUNIT_ASSERT( !ep.empty() );
472 CPPUNIT_CHECK( pVal->nKey == ep->nKey );
473 CPPUNIT_CHECK( pVal->nVal == (*ep).nVal );
478 CPPUNIT_CHECK( s.get_with( other_item( nKey ), other_less() ) == nullptr );
479 CPPUNIT_CHECK( !s.extract_with( other_item(nKey), other_less() ));
480 CPPUNIT_CHECK( ep.empty() );
483 CPPUNIT_CHECK( s.empty() );
484 CPPUNIT_CHECK( check_size( s, 0 ));
487 CPPUNIT_CHECK( s.get( int( nLimit / 2 ) ) == nullptr );
488 ep = s.extract( int( nLimit / 2 ) );
489 CPPUNIT_CHECK( !ep );
490 CPPUNIT_CHECK( ep.empty() );
499 void test_int_with( Set& s)
501 typedef typename Set::value_type value_type;
507 CPPUNIT_ASSERT( !s.find( 10 ) );
508 CPPUNIT_ASSERT( s.insert( 10 ));
509 CPPUNIT_ASSERT( !s.empty() );
510 CPPUNIT_ASSERT( check_size( s, 1 ));
511 CPPUNIT_ASSERT( s.find( 10 ) );
513 CPPUNIT_ASSERT( !s.insert( 10 ));
514 CPPUNIT_ASSERT( !s.empty() );
515 CPPUNIT_ASSERT( check_size( s, 1 ));
517 CPPUNIT_ASSERT( !s.find_with( 20, less<value_type>() ) );
518 CPPUNIT_ASSERT( s.insert( std::make_pair(20, 25) ));
519 CPPUNIT_ASSERT( !s.empty() );
520 CPPUNIT_ASSERT( check_size( s, 2 ));
521 CPPUNIT_ASSERT( s.find_with( 10, less<value_type>() ) );
522 CPPUNIT_ASSERT( s.find( key = 20 ) );
523 CPPUNIT_ASSERT( s.find_with( key, less<value_type>(), find_functor() ) );
527 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
528 CPPUNIT_ASSERT( f.m_found.nKey == 20 );
529 CPPUNIT_ASSERT( f.m_found.nVal == 25 );
530 CPPUNIT_ASSERT( f.m_found.nFindCount == 1 );
532 CPPUNIT_ASSERT( s.find( key, find_functor() ) );
536 CPPUNIT_ASSERT( s.find_with( key, less<value_type>(), std::ref( f ) ) );
537 CPPUNIT_ASSERT( f.m_found.nKey == 20 );
538 CPPUNIT_ASSERT( f.m_found.nVal == 25 );
539 CPPUNIT_ASSERT( f.m_found.nFindCount == 2 );
541 CPPUNIT_ASSERT( !s.empty() );
542 CPPUNIT_ASSERT( check_size( s, 2 ));
544 CPPUNIT_ASSERT( !s.find( 25 ) );
545 CPPUNIT_ASSERT( s.insert( std::make_pair(25, -1), insert_functor() ));
546 CPPUNIT_ASSERT( !s.empty() );
547 CPPUNIT_ASSERT( check_size( s, 3 ));
551 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
552 CPPUNIT_ASSERT( f.m_found.nKey == 25 );
553 CPPUNIT_ASSERT( f.m_found.nVal == 2500 );
560 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
561 CPPUNIT_ASSERT( f.m_found.nKey == 10 );
562 CPPUNIT_ASSERT( f.m_found.nVal == 10 );
563 CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 );
564 CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 );
566 std::pair<bool, bool> ensureResult = s.ensure( key, ensure_functor() );
567 CPPUNIT_ASSERT( ensureResult.first && !ensureResult.second );
568 CPPUNIT_ASSERT( !s.empty() );
569 CPPUNIT_ASSERT( check_size( s, 3 ));
572 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
573 CPPUNIT_ASSERT( f.m_found.nKey == 10 );
574 CPPUNIT_ASSERT( f.m_found.nVal == 10 );
575 CPPUNIT_ASSERT( f.m_found.nEnsureCount == 1 );
576 CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 );
579 ensureResult = s.ensure( std::make_pair(13, 1300), ensure_functor() );
580 CPPUNIT_ASSERT( ensureResult.first && ensureResult.second );
581 CPPUNIT_ASSERT( !s.empty() );
582 CPPUNIT_ASSERT( check_size( s, 4 ));
586 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
587 CPPUNIT_ASSERT( f.m_found.nKey == 13 );
588 CPPUNIT_ASSERT( f.m_found.nVal == 1300 );
589 CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 );
590 CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 1 );
594 CPPUNIT_ASSERT( s.erase(13) );
595 CPPUNIT_ASSERT( !s.find( 13 ));
596 CPPUNIT_ASSERT( !s.empty() );
597 CPPUNIT_ASSERT( check_size( s, 3 ));
598 CPPUNIT_ASSERT( !s.erase(13) );
599 CPPUNIT_ASSERT( !s.empty() );
600 CPPUNIT_ASSERT( check_size( s, 3 ));
602 CPPUNIT_ASSERT( s.find( 10 ));
603 CPPUNIT_ASSERT( s.erase_with( 10, less<value_type>() ));
604 CPPUNIT_ASSERT( !s.find( 10 ));
605 CPPUNIT_ASSERT( !s.empty() );
606 CPPUNIT_ASSERT( check_size( s, 2 ));
607 CPPUNIT_ASSERT( !s.erase_with(10, less<value_type>()) );
608 CPPUNIT_ASSERT( !s.empty() );
609 CPPUNIT_ASSERT( check_size( s, 2 ));
611 CPPUNIT_ASSERT( s.find(20) );
614 CPPUNIT_ASSERT( s.erase( 20, std::ref( f ) ) );
615 CPPUNIT_ASSERT( f.m_found.nKey == 20 );
616 CPPUNIT_ASSERT( f.m_found.nVal == 25 );
618 CPPUNIT_ASSERT( s.insert(235))
619 CPPUNIT_ASSERT( s.erase_with( 235, less<value_type>(), std::ref( f ) ) );
620 CPPUNIT_ASSERT( f.m_found.nKey == 235 );
621 CPPUNIT_ASSERT( f.m_found.nVal == 235 );
623 CPPUNIT_ASSERT( !s.find( 20 ));
624 CPPUNIT_ASSERT( !s.empty() );
625 CPPUNIT_ASSERT( check_size( s, 1 ));
628 CPPUNIT_ASSERT( s.empty() );
629 CPPUNIT_ASSERT( check_size( s, 0 ));
632 CPPUNIT_ASSERT( s.emplace( 151 )) ; // key = 151, val = 151
633 CPPUNIT_ASSERT( s.emplace( 174, 471 )) ; // key = 174, val = 471
634 CPPUNIT_ASSERT( s.emplace( std::make_pair( 190, 91 ) )) ; // key == 190, val = 91
635 CPPUNIT_ASSERT( !s.empty() );
636 CPPUNIT_ASSERT( check_size( s, 3 ));
638 CPPUNIT_ASSERT( s.find(151));
639 CPPUNIT_ASSERT( s.find_with(174, less<value_type>()));
640 CPPUNIT_ASSERT( s.find(190));
645 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
646 CPPUNIT_ASSERT( f.m_found.nKey == 151 );
647 CPPUNIT_ASSERT( f.m_found.nVal == 151 );
650 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
651 CPPUNIT_ASSERT( f.m_found.nKey == 174 );
652 CPPUNIT_ASSERT( f.m_found.nVal == 471 );
655 CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) );
656 CPPUNIT_ASSERT( f.m_found.nKey == 190 );
657 CPPUNIT_ASSERT( f.m_found.nVal == 91 );
661 CPPUNIT_ASSERT( s.empty() );
662 CPPUNIT_ASSERT( check_size( s, 0 ));
669 typedef typename Set::value_type value_type;
670 typedef typename Set::iterator iterator;
671 typedef typename Set::const_iterator const_iterator;
677 CPPUNIT_ASSERT( s.empty() );
678 CPPUNIT_ASSERT( check_size( s, 0 ));
682 CPPUNIT_ASSERT( it != s.end() );
683 CPPUNIT_ASSERT( it->key() == 10 );
684 CPPUNIT_ASSERT( it->val() == 10 );
685 CPPUNIT_ASSERT( !s.empty() );
686 CPPUNIT_ASSERT( check_size( s, 1 ));
687 CPPUNIT_ASSERT( s.insert( 10 ) == s.end() );
689 it = s.insert( std::make_pair( 50, 25 ));
690 CPPUNIT_ASSERT( it != s.end() );
691 CPPUNIT_ASSERT( it->key() == 50 );
692 CPPUNIT_ASSERT( it->val() == 25 );
693 CPPUNIT_ASSERT( !s.empty() );
694 CPPUNIT_ASSERT( check_size( s, 2 ));
695 CPPUNIT_ASSERT( s.insert( 50 ) == s.end() );
698 std::pair< iterator, bool> ensureResult;
699 ensureResult = s.ensure( 20 );
700 CPPUNIT_ASSERT( ensureResult.first != s.end() );
701 CPPUNIT_ASSERT( ensureResult.second );
702 CPPUNIT_ASSERT( ensureResult.first->key() == 20 );
703 CPPUNIT_ASSERT( ensureResult.first->val() == 20 );
704 CPPUNIT_ASSERT( !s.empty() );
705 CPPUNIT_ASSERT( check_size( s, 3 ));
707 ensureResult = s.ensure( std::make_pair( 20, 200 ));
708 CPPUNIT_ASSERT( ensureResult.first != s.end() );
709 CPPUNIT_ASSERT( !ensureResult.second );
710 CPPUNIT_ASSERT( ensureResult.first->key() == 20 );
711 CPPUNIT_ASSERT( ensureResult.first->val() == 20 );
712 CPPUNIT_ASSERT( !s.empty() );
713 CPPUNIT_ASSERT( check_size( s, 3 ));
714 ensureResult.first->nVal = 22;
716 ensureResult = s.ensure( std::make_pair( 30, 33 ));
717 CPPUNIT_ASSERT( ensureResult.first != s.end() );
718 CPPUNIT_ASSERT( ensureResult.second );
719 CPPUNIT_ASSERT( ensureResult.first->key() == 30 );
720 CPPUNIT_ASSERT( ensureResult.first->val() == 33 );
721 CPPUNIT_ASSERT( !s.empty() );
722 CPPUNIT_ASSERT( check_size( s, 4 ));
726 CPPUNIT_ASSERT( it != s.end() );
727 CPPUNIT_ASSERT( it->key() == 10 );
728 CPPUNIT_ASSERT( it->val() == 10 );
730 it = s.find_with( 20, less<value_type>() );
731 CPPUNIT_ASSERT( it != s.end() );
732 CPPUNIT_ASSERT( it->key() == 20 );
733 CPPUNIT_ASSERT( it->val() == 22 );
736 CPPUNIT_ASSERT( it != s.end() );
737 CPPUNIT_ASSERT( it->key() == 30 );
738 CPPUNIT_ASSERT( it->val() == 33 );
741 CPPUNIT_ASSERT( it == s.end() );
744 CPPUNIT_ASSERT( it != s.end() );
745 CPPUNIT_ASSERT( it->key() == 50 );
746 CPPUNIT_ASSERT( it->val() == 25 );
749 it = s.emplace( 151 ) ; // key = 151, val = 151
750 CPPUNIT_ASSERT( it != s.end() );
751 CPPUNIT_ASSERT( it->key() == 151 );
752 CPPUNIT_ASSERT( it->val() == 151 );
754 it = s.emplace( 174, 471 ) ; // key == 174, val = 471
755 CPPUNIT_ASSERT( it != s.end() );
756 CPPUNIT_ASSERT( it->key() == 174 );
757 CPPUNIT_ASSERT( it->val() == 471 );
759 it = s.emplace( std::make_pair( 190, 91 )) ; // key == 190, val = 91
760 CPPUNIT_ASSERT( it != s.end() );
761 CPPUNIT_ASSERT( it->key() == 190 );
762 CPPUNIT_ASSERT( it->val() == 91 );
765 CPPUNIT_ASSERT( it != s.end() );
766 CPPUNIT_ASSERT( it->key() == 174 );
767 CPPUNIT_ASSERT( it->val() == 471 );
769 it = s.find_with( 190, less<value_type>() );
770 CPPUNIT_ASSERT( it != s.end() );
771 CPPUNIT_ASSERT( it->key() == 190 );
772 CPPUNIT_ASSERT( it->val() == 91 );
775 CPPUNIT_ASSERT( it != s.end() );
776 CPPUNIT_ASSERT( it->key() == 151 );
777 CPPUNIT_ASSERT( it->val() == 151 );
780 //CPPUNIT_ASSERT( s.empty() );
781 //CPPUNIT_ASSERT( check_size( s, 0 ));
788 for ( int i = 0; i < 500; ++i ) {
789 CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ) != s.end() );
791 for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
793 CPPUNIT_CHECK( it2 == it );
794 CPPUNIT_CHECK( it2 != itEnd );
795 CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal );
796 it->nVal = (*it).nKey;
799 Set const& refSet = s;
800 for ( const_iterator it = refSet.begin(), itEnd = refSet.end(); it != itEnd; ++it ) {
801 CPPUNIT_ASSERT( (*it).nKey == it->nVal );
807 void test_int_nogc_unordered()
809 typedef typename Set::value_type value_type;
810 typedef typename Set::iterator iterator;
811 typedef typename Set::const_iterator const_iterator;
817 CPPUNIT_ASSERT( s.empty() );
818 CPPUNIT_ASSERT( check_size( s, 0 ));
822 CPPUNIT_ASSERT( it != s.end() );
823 CPPUNIT_ASSERT( it->key() == 10 );
824 CPPUNIT_ASSERT( it->val() == 10 );
825 CPPUNIT_ASSERT( !s.empty() );
826 CPPUNIT_ASSERT( check_size( s, 1 ));
827 CPPUNIT_ASSERT( s.insert( 10 ) == s.end() );
829 it = s.insert( std::make_pair( 50, 25 ));
830 CPPUNIT_ASSERT( it != s.end() );
831 CPPUNIT_ASSERT( it->key() == 50 );
832 CPPUNIT_ASSERT( it->val() == 25 );
833 CPPUNIT_ASSERT( !s.empty() );
834 CPPUNIT_ASSERT( check_size( s, 2 ));
835 CPPUNIT_ASSERT( s.insert( 50 ) == s.end() );
838 std::pair< iterator, bool> ensureResult;
839 ensureResult = s.ensure( 20 );
840 CPPUNIT_ASSERT( ensureResult.first != s.end() );
841 CPPUNIT_ASSERT( ensureResult.second );
842 CPPUNIT_ASSERT( ensureResult.first->key() == 20 );
843 CPPUNIT_ASSERT( ensureResult.first->val() == 20 );
844 CPPUNIT_ASSERT( !s.empty() );
845 CPPUNIT_ASSERT( check_size( s, 3 ));
847 ensureResult = s.ensure( std::make_pair( 20, 200 ));
848 CPPUNIT_ASSERT( ensureResult.first != s.end() );
849 CPPUNIT_ASSERT( !ensureResult.second );
850 CPPUNIT_ASSERT( ensureResult.first->key() == 20 );
851 CPPUNIT_ASSERT( ensureResult.first->val() == 20 );
852 CPPUNIT_ASSERT( !s.empty() );
853 CPPUNIT_ASSERT( check_size( s, 3 ));
854 ensureResult.first->nVal = 22;
856 ensureResult = s.ensure( std::make_pair( 30, 33 ));
857 CPPUNIT_ASSERT( ensureResult.first != s.end() );
858 CPPUNIT_ASSERT( ensureResult.second );
859 CPPUNIT_ASSERT( ensureResult.first->key() == 30 );
860 CPPUNIT_ASSERT( ensureResult.first->val() == 33 );
861 CPPUNIT_ASSERT( !s.empty() );
862 CPPUNIT_ASSERT( check_size( s, 4 ));
866 CPPUNIT_ASSERT( it != s.end() );
867 CPPUNIT_ASSERT( it->key() == 10 );
868 CPPUNIT_ASSERT( it->val() == 10 );
870 it = s.find_with( 20, equal<value_type>() );
871 CPPUNIT_ASSERT( it != s.end() );
872 CPPUNIT_ASSERT( it->key() == 20 );
873 CPPUNIT_ASSERT( it->val() == 22 );
876 CPPUNIT_ASSERT( it != s.end() );
877 CPPUNIT_ASSERT( it->key() == 30 );
878 CPPUNIT_ASSERT( it->val() == 33 );
881 CPPUNIT_ASSERT( it == s.end() );
884 CPPUNIT_ASSERT( it != s.end() );
885 CPPUNIT_ASSERT( it->key() == 50 );
886 CPPUNIT_ASSERT( it->val() == 25 );
889 it = s.emplace( 151 ) ; // key = 151, val = 151
890 CPPUNIT_ASSERT( it != s.end() );
891 CPPUNIT_ASSERT( it->key() == 151 );
892 CPPUNIT_ASSERT( it->val() == 151 );
894 it = s.emplace( 174, 471 ) ; // key == 174, val = 471
895 CPPUNIT_ASSERT( it != s.end() );
896 CPPUNIT_ASSERT( it->key() == 174 );
897 CPPUNIT_ASSERT( it->val() == 471 );
899 it = s.emplace( std::make_pair( 190, 91 )) ; // key == 190, val = 91
900 CPPUNIT_ASSERT( it != s.end() );
901 CPPUNIT_ASSERT( it->key() == 190 );
902 CPPUNIT_ASSERT( it->val() == 91 );
905 CPPUNIT_ASSERT( it != s.end() );
906 CPPUNIT_ASSERT( it->key() == 174 );
907 CPPUNIT_ASSERT( it->val() == 471 );
909 it = s.find_with( 190, equal<value_type>() );
910 CPPUNIT_ASSERT( it != s.end() );
911 CPPUNIT_ASSERT( it->key() == 190 );
912 CPPUNIT_ASSERT( it->val() == 91 );
915 CPPUNIT_ASSERT( it != s.end() );
916 CPPUNIT_ASSERT( it->key() == 151 );
917 CPPUNIT_ASSERT( it->val() == 151 );
920 //CPPUNIT_ASSERT( s.empty() );
921 //CPPUNIT_ASSERT( check_size( s, 0 ));
928 for ( int i = 0; i < 500; ++i ) {
929 CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ) != s.end() );
931 for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
933 CPPUNIT_CHECK( it2 == it );
934 CPPUNIT_CHECK( it2 != itEnd );
935 CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal );
936 it->nVal = (*it).nKey;
939 Set const& refSet = s;
940 for ( const_iterator it = refSet.begin(), itEnd = refSet.end(); it != itEnd; ++it ) {
941 CPPUNIT_ASSERT( (*it).nKey == it->nVal );
948 typedef typename Set::value_type value_type;
949 typedef typename Set::iterator iterator;
950 typedef typename Set::const_iterator const_iterator;
954 const size_t nMaxCount = 500;
955 for ( int i = 0; size_t(i) < nMaxCount; ++i ) {
956 CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ));
960 typename Set::iterator it( s.begin() );
961 typename Set::const_iterator cit( s.cbegin() );
962 CPPUNIT_CHECK( it == cit );
963 CPPUNIT_CHECK( it != s.end() );
964 CPPUNIT_CHECK( it != s.cend() );
965 CPPUNIT_CHECK( cit != s.end() );
966 CPPUNIT_CHECK( cit != s.cend() );
968 CPPUNIT_CHECK( it != cit );
969 CPPUNIT_CHECK( it != s.end() );
970 CPPUNIT_CHECK( it != s.cend() );
971 CPPUNIT_CHECK( cit != s.end() );
972 CPPUNIT_CHECK( cit != s.cend() );
974 CPPUNIT_CHECK( it == cit );
975 CPPUNIT_CHECK( it != s.end() );
976 CPPUNIT_CHECK( it != s.cend() );
977 CPPUNIT_CHECK( cit != s.end() );
978 CPPUNIT_CHECK( cit != s.cend() );
982 for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
983 CPPUNIT_ASSERT_EX( (*it).nKey * 2 == it->nVal,
984 "Step " << nCount << ": Iterator key=" << it->nKey << ", value expected=" << it->nKey * 2 << ", value real=" << it->nVal
986 it->nVal = (*it).nKey;
989 CPPUNIT_ASSERT( nCount == nMaxCount );
992 Set const& refSet = s;
993 for ( const_iterator it = refSet.begin(), itEnd = refSet.end(); it != itEnd; ++it ) {
994 CPPUNIT_ASSERT_EX( (*it).nKey == it->nVal,
995 "Step " << nCount << ": Iterator key=" << it->nKey << ", value expected=" << it->nKey << ", value real=" << it->nVal
999 CPPUNIT_ASSERT( nCount == nMaxCount );
1002 void Michael_HP_cmp();
1003 void Michael_HP_less();
1004 void Michael_HP_cmpmix();
1006 void Michael_DHP_cmp();
1007 void Michael_DHP_less();
1008 void Michael_DHP_cmpmix();
1010 void Michael_RCU_GPI_cmp();
1011 void Michael_RCU_GPI_less();
1012 void Michael_RCU_GPI_cmpmix();
1014 void Michael_RCU_GPT_cmp();
1015 void Michael_RCU_GPT_less();
1016 void Michael_RCU_GPT_cmpmix();
1018 void Michael_RCU_GPB_cmp();
1019 void Michael_RCU_GPB_less();
1020 void Michael_RCU_GPB_cmpmix();
1022 void Michael_RCU_SHT_cmp();
1023 void Michael_RCU_SHT_less();
1024 void Michael_RCU_SHT_cmpmix();
1026 void Michael_RCU_SHB_cmp();
1027 void Michael_RCU_SHB_less();
1028 void Michael_RCU_SHB_cmpmix();
1030 void Michael_nogc_cmp();
1031 void Michael_nogc_less();
1032 void Michael_nogc_cmpmix();
1035 void Lazy_HP_less();
1036 void Lazy_HP_cmpmix();
1038 void Lazy_DHP_cmp();
1039 void Lazy_DHP_less();
1040 void Lazy_DHP_cmpmix();
1042 void Lazy_RCU_GPI_cmp();
1043 void Lazy_RCU_GPI_less();
1044 void Lazy_RCU_GPI_cmpmix();
1046 void Lazy_RCU_GPB_cmp();
1047 void Lazy_RCU_GPB_less();
1048 void Lazy_RCU_GPB_cmpmix();
1050 void Lazy_RCU_GPT_cmp();
1051 void Lazy_RCU_GPT_less();
1052 void Lazy_RCU_GPT_cmpmix();
1054 void Lazy_RCU_SHB_cmp();
1055 void Lazy_RCU_SHB_less();
1056 void Lazy_RCU_SHB_cmpmix();
1058 void Lazy_RCU_SHT_cmp();
1059 void Lazy_RCU_SHT_less();
1060 void Lazy_RCU_SHT_cmpmix();
1062 void Lazy_nogc_cmp();
1063 void Lazy_nogc_less();
1064 void Lazy_nogc_equal();
1065 void Lazy_nogc_cmpmix();
1067 void Split_HP_cmp();
1068 void Split_HP_less();
1069 void Split_HP_cmpmix();
1070 void Split_HP_cmpmix_stat();
1072 void Split_DHP_cmp();
1073 void Split_DHP_less();
1074 void Split_DHP_cmpmix();
1075 void Split_DHP_cmpmix_stat();
1077 void Split_RCU_GPI_cmp();
1078 void Split_RCU_GPI_less();
1079 void Split_RCU_GPI_cmpmix();
1080 void Split_RCU_GPI_cmpmix_stat();
1082 void Split_RCU_GPB_cmp();
1083 void Split_RCU_GPB_less();
1084 void Split_RCU_GPB_cmpmix();
1085 void Split_RCU_GPB_cmpmix_stat();
1087 void Split_RCU_GPT_cmp();
1088 void Split_RCU_GPT_less();
1089 void Split_RCU_GPT_cmpmix();
1090 void Split_RCU_GPT_cmpmix_stat();
1092 void Split_RCU_SHB_cmp();
1093 void Split_RCU_SHB_less();
1094 void Split_RCU_SHB_cmpmix();
1095 void Split_RCU_SHB_cmpmix_stat();
1097 void Split_RCU_SHT_cmp();
1098 void Split_RCU_SHT_less();
1099 void Split_RCU_SHT_cmpmix();
1100 void Split_RCU_SHT_cmpmix_stat();
1102 void Split_nogc_cmp();
1103 void Split_nogc_less();
1104 void Split_nogc_cmpmix();
1105 void Split_nogc_cmpmix_stat();
1108 void Split_Lazy_HP_cmp();
1109 void Split_Lazy_HP_less();
1110 void Split_Lazy_HP_cmpmix();
1111 void Split_Lazy_HP_cmpmix_stat();
1113 void Split_Lazy_DHP_cmp();
1114 void Split_Lazy_DHP_less();
1115 void Split_Lazy_DHP_cmpmix();
1116 void Split_Lazy_DHP_cmpmix_stat();
1118 void Split_Lazy_RCU_GPI_cmp();
1119 void Split_Lazy_RCU_GPI_less();
1120 void Split_Lazy_RCU_GPI_cmpmix();
1121 void Split_Lazy_RCU_GPI_cmpmix_stat();
1123 void Split_Lazy_RCU_GPB_cmp();
1124 void Split_Lazy_RCU_GPB_less();
1125 void Split_Lazy_RCU_GPB_cmpmix();
1126 void Split_Lazy_RCU_GPB_cmpmix_stat();
1128 void Split_Lazy_RCU_GPT_cmp();
1129 void Split_Lazy_RCU_GPT_less();
1130 void Split_Lazy_RCU_GPT_cmpmix();
1131 void Split_Lazy_RCU_GPT_cmpmix_stat();
1133 void Split_Lazy_RCU_SHB_cmp();
1134 void Split_Lazy_RCU_SHB_less();
1135 void Split_Lazy_RCU_SHB_cmpmix();
1136 void Split_Lazy_RCU_SHB_cmpmix_stat();
1138 void Split_Lazy_RCU_SHT_cmp();
1139 void Split_Lazy_RCU_SHT_less();
1140 void Split_Lazy_RCU_SHT_cmpmix();
1141 void Split_Lazy_RCU_SHT_cmpmix_stat();
1143 void Split_Lazy_nogc_cmp();
1144 void Split_Lazy_nogc_less();
1145 void Split_Lazy_nogc_cmpmix();
1146 void Split_Lazy_nogc_cmpmix_stat();
1148 CPPUNIT_TEST_SUITE(HashSetHdrTest)
1149 CPPUNIT_TEST(Michael_HP_cmp)
1150 CPPUNIT_TEST(Michael_HP_less)
1151 CPPUNIT_TEST(Michael_HP_cmpmix)
1153 CPPUNIT_TEST(Michael_DHP_cmp)
1154 CPPUNIT_TEST(Michael_DHP_less)
1155 CPPUNIT_TEST(Michael_DHP_cmpmix)
1157 CPPUNIT_TEST(Michael_RCU_GPI_cmp)
1158 CPPUNIT_TEST(Michael_RCU_GPI_less)
1159 CPPUNIT_TEST(Michael_RCU_GPI_cmpmix)
1161 CPPUNIT_TEST(Michael_RCU_GPB_cmp)
1162 CPPUNIT_TEST(Michael_RCU_GPB_less)
1163 CPPUNIT_TEST(Michael_RCU_GPB_cmpmix)
1165 CPPUNIT_TEST(Michael_RCU_GPT_cmp)
1166 CPPUNIT_TEST(Michael_RCU_GPT_less)
1167 CPPUNIT_TEST(Michael_RCU_GPT_cmpmix)
1169 CPPUNIT_TEST(Michael_RCU_SHB_cmp)
1170 CPPUNIT_TEST(Michael_RCU_SHB_less)
1171 CPPUNIT_TEST(Michael_RCU_SHB_cmpmix)
1173 CPPUNIT_TEST(Michael_RCU_SHT_cmp)
1174 CPPUNIT_TEST(Michael_RCU_SHT_less)
1175 CPPUNIT_TEST(Michael_RCU_SHT_cmpmix)
1177 CPPUNIT_TEST(Michael_nogc_cmp)
1178 CPPUNIT_TEST(Michael_nogc_less)
1179 CPPUNIT_TEST(Michael_nogc_cmpmix)
1181 CPPUNIT_TEST(Lazy_HP_cmp)
1182 CPPUNIT_TEST(Lazy_HP_less)
1183 CPPUNIT_TEST(Lazy_HP_cmpmix)
1185 CPPUNIT_TEST(Lazy_DHP_cmp)
1186 CPPUNIT_TEST(Lazy_DHP_less)
1187 CPPUNIT_TEST(Lazy_DHP_cmpmix)
1189 CPPUNIT_TEST(Lazy_RCU_GPI_cmp)
1190 CPPUNIT_TEST(Lazy_RCU_GPI_less)
1191 CPPUNIT_TEST(Lazy_RCU_GPI_cmpmix)
1193 CPPUNIT_TEST(Lazy_RCU_GPB_cmp)
1194 CPPUNIT_TEST(Lazy_RCU_GPB_less)
1195 CPPUNIT_TEST(Lazy_RCU_GPB_cmpmix)
1197 CPPUNIT_TEST(Lazy_RCU_GPT_cmp)
1198 CPPUNIT_TEST(Lazy_RCU_GPT_less)
1199 CPPUNIT_TEST(Lazy_RCU_GPT_cmpmix)
1201 CPPUNIT_TEST(Lazy_RCU_SHB_cmp)
1202 CPPUNIT_TEST(Lazy_RCU_SHB_less)
1203 CPPUNIT_TEST(Lazy_RCU_SHB_cmpmix)
1205 CPPUNIT_TEST(Lazy_RCU_SHT_cmp)
1206 CPPUNIT_TEST(Lazy_RCU_SHT_less)
1207 CPPUNIT_TEST(Lazy_RCU_SHT_cmpmix)
1209 CPPUNIT_TEST(Lazy_nogc_cmp)
1210 CPPUNIT_TEST(Lazy_nogc_less)
1211 CPPUNIT_TEST(Lazy_nogc_equal)
1212 CPPUNIT_TEST(Lazy_nogc_cmpmix)
1214 CPPUNIT_TEST(Split_HP_cmp)
1215 CPPUNIT_TEST(Split_HP_less)
1216 CPPUNIT_TEST(Split_HP_cmpmix)
1217 CPPUNIT_TEST( Split_HP_cmpmix_stat )
1219 CPPUNIT_TEST(Split_DHP_cmp)
1220 CPPUNIT_TEST(Split_DHP_less)
1221 CPPUNIT_TEST(Split_DHP_cmpmix)
1222 CPPUNIT_TEST( Split_DHP_cmpmix_stat )
1224 CPPUNIT_TEST(Split_RCU_GPI_cmp)
1225 CPPUNIT_TEST(Split_RCU_GPI_less)
1226 CPPUNIT_TEST(Split_RCU_GPI_cmpmix)
1227 CPPUNIT_TEST( Split_RCU_GPI_cmpmix_stat )
1229 CPPUNIT_TEST(Split_RCU_GPB_cmp)
1230 CPPUNIT_TEST(Split_RCU_GPB_less)
1231 CPPUNIT_TEST(Split_RCU_GPB_cmpmix)
1232 CPPUNIT_TEST( Split_RCU_GPB_cmpmix_stat )
1234 CPPUNIT_TEST(Split_RCU_GPT_cmp)
1235 CPPUNIT_TEST(Split_RCU_GPT_less)
1236 CPPUNIT_TEST(Split_RCU_GPT_cmpmix)
1237 CPPUNIT_TEST( Split_RCU_GPT_cmpmix_stat )
1239 CPPUNIT_TEST(Split_RCU_SHB_cmp)
1240 CPPUNIT_TEST(Split_RCU_SHB_less)
1241 CPPUNIT_TEST(Split_RCU_SHB_cmpmix)
1242 CPPUNIT_TEST( Split_RCU_SHB_cmpmix_stat )
1244 CPPUNIT_TEST(Split_RCU_SHT_cmp)
1245 CPPUNIT_TEST(Split_RCU_SHT_less)
1246 CPPUNIT_TEST(Split_RCU_SHT_cmpmix)
1247 CPPUNIT_TEST( Split_RCU_SHT_cmpmix_stat )
1249 CPPUNIT_TEST(Split_nogc_cmp)
1250 CPPUNIT_TEST(Split_nogc_less)
1251 CPPUNIT_TEST(Split_nogc_cmpmix)
1252 CPPUNIT_TEST( Split_nogc_cmpmix_stat )
1254 CPPUNIT_TEST(Split_Lazy_HP_cmp)
1255 CPPUNIT_TEST(Split_Lazy_HP_less)
1256 CPPUNIT_TEST(Split_Lazy_HP_cmpmix)
1257 CPPUNIT_TEST( Split_Lazy_HP_cmpmix_stat )
1259 CPPUNIT_TEST(Split_Lazy_DHP_cmp)
1260 CPPUNIT_TEST(Split_Lazy_DHP_less)
1261 CPPUNIT_TEST(Split_Lazy_DHP_cmpmix)
1262 CPPUNIT_TEST( Split_Lazy_DHP_cmpmix_stat )
1264 CPPUNIT_TEST(Split_Lazy_RCU_GPI_cmp)
1265 CPPUNIT_TEST(Split_Lazy_RCU_GPI_less)
1266 CPPUNIT_TEST(Split_Lazy_RCU_GPI_cmpmix)
1267 CPPUNIT_TEST( Split_Lazy_RCU_GPI_cmpmix_stat )
1269 CPPUNIT_TEST(Split_Lazy_RCU_GPB_cmp)
1270 CPPUNIT_TEST(Split_Lazy_RCU_GPB_less)
1271 CPPUNIT_TEST(Split_Lazy_RCU_GPB_cmpmix)
1272 CPPUNIT_TEST( Split_Lazy_RCU_GPB_cmpmix_stat )
1274 CPPUNIT_TEST(Split_Lazy_RCU_GPT_cmp)
1275 CPPUNIT_TEST(Split_Lazy_RCU_GPT_less)
1276 CPPUNIT_TEST(Split_Lazy_RCU_GPT_cmpmix)
1277 CPPUNIT_TEST( Split_Lazy_RCU_GPT_cmpmix_stat )
1279 CPPUNIT_TEST(Split_Lazy_RCU_SHB_cmp)
1280 CPPUNIT_TEST(Split_Lazy_RCU_SHB_less)
1281 CPPUNIT_TEST(Split_Lazy_RCU_SHB_cmpmix)
1282 CPPUNIT_TEST( Split_Lazy_RCU_SHB_cmpmix_stat )
1284 CPPUNIT_TEST(Split_Lazy_RCU_SHT_cmp)
1285 CPPUNIT_TEST(Split_Lazy_RCU_SHT_less)
1286 CPPUNIT_TEST(Split_Lazy_RCU_SHT_cmpmix)
1287 CPPUNIT_TEST( Split_Lazy_RCU_SHT_cmpmix_stat )
1289 CPPUNIT_TEST(Split_Lazy_nogc_cmp)
1290 CPPUNIT_TEST(Split_Lazy_nogc_less)
1291 CPPUNIT_TEST(Split_Lazy_nogc_cmpmix)
1292 CPPUNIT_TEST( Split_Lazy_nogc_cmpmix_stat )
1294 CPPUNIT_TEST_SUITE_END()
1300 #endif // CDSTEST_HDR_SET_H