3 #ifndef CDSTEST_HDR_MAP_H
4 #define CDSTEST_HDR_MAP_H
5 #include "size_check.h"
7 #include "cppunit/cppunit_proxy.h"
8 #include <cds/os/timer.h>
9 #include <cds/opt/hash.h>
10 #include <functional> // ref
12 namespace cds { namespace container {}}
15 using misc::check_size;
17 namespace cc = cds::container;
18 namespace co = cds::opt;
20 // MichaelHashSet based on MichaelList
21 class HashMapHdrTest: public CppUnitMini::TestCase
37 value_type( value_type&& v )
41 value_type( value_type const& v )
45 value_type& operator=( value_type const& v )
52 typedef std::pair<key_type const, value_type> pair_type;
56 bool operator ()(int v1, int v2 ) const
63 int operator ()(int v1, int v2 ) const
67 return v1 > v2 ? 1 : 0;
72 bool operator ()(int v1, int v2 ) const
79 size_t operator()( int i ) const
81 return co::v::hash<int>()( i );
85 size_t operator()( T const& i ) const
87 return co::v::hash<int>()( i.nKey );
91 struct simple_item_counter {
113 operator size_t() const
119 template <typename Map>
120 struct insert_functor
122 typedef typename Map::value_type pair_type;
125 void operator()( pair_type& item )
127 item.second.m_val = item.first * 3;
131 void operator()( bool bNew, pair_type& item )
134 item.second.m_val = item.first * 2;
136 item.second.m_val = item.first * 5;
143 check_value( int nExpected )
144 : m_nExpected( nExpected )
147 template <typename T>
148 void operator ()( T& pair )
150 CPPUNIT_ASSERT_CURRENT( pair.second.m_val == m_nExpected );
152 template <typename T, typename Q>
153 void operator ()( T& pair, Q )
155 CPPUNIT_ASSERT_CURRENT( pair.second.m_val == m_nExpected );
159 struct extract_functor
162 void operator()( pair_type const& val )
164 *m_pVal = val.second.m_val;
171 other_item( int key )
178 bool operator ()(int v1, other_item const& v2 ) const
182 bool operator ()(other_item const& v1, int v2 ) const
197 CPPUNIT_ASSERT( m.empty() );
199 const int nLimit = 100;
200 typename Map::guarded_ptr gp;
201 int arrRandom[nLimit];
202 for ( int i = 0; i < nLimit; ++i )
204 shuffle( arrRandom, arrRandom + nLimit );
206 for ( int i = 0; i < nLimit; ++i )
207 CPPUNIT_ASSERT( m.insert( arrRandom[i], arrRandom[i] ));
209 for ( int i = 0; i < nLimit; ++i ) {
210 int nKey = arrRandom[i];
212 CPPUNIT_ASSERT( gp );
213 CPPUNIT_ASSERT( !gp.empty());
214 CPPUNIT_CHECK( gp->first == nKey );
215 CPPUNIT_CHECK( gp->second.m_val == nKey );
218 gp = m.extract( nKey );
219 CPPUNIT_ASSERT( gp );
220 CPPUNIT_ASSERT( !gp.empty());
221 CPPUNIT_CHECK( gp->first == nKey );
222 CPPUNIT_CHECK( gp->second.m_val == nKey );
226 CPPUNIT_CHECK( !gp );
228 CPPUNIT_CHECK( !m.extract(nKey));
229 CPPUNIT_CHECK( gp.empty());
231 CPPUNIT_ASSERT( m.empty() );
233 for ( int i = 0; i < nLimit; ++i )
234 CPPUNIT_ASSERT( m.insert( arrRandom[i], arrRandom[i] ));
236 for ( int i = 0; i < nLimit; ++i ) {
237 int nKey = arrRandom[i];
238 gp = m.get_with( other_item( nKey ), other_less() );
239 CPPUNIT_ASSERT( gp );
240 CPPUNIT_ASSERT( !gp.empty());
241 CPPUNIT_CHECK( gp->first == nKey );
242 CPPUNIT_CHECK( gp->second.m_val == nKey );
245 gp = m.extract_with( other_item( nKey ), other_less() );
246 CPPUNIT_ASSERT( gp );
247 CPPUNIT_ASSERT( !gp.empty());
248 CPPUNIT_CHECK( gp->first == nKey );
249 CPPUNIT_CHECK( gp->second.m_val == nKey );
252 gp = m.get_with( other_item( nKey ), other_less() );
253 CPPUNIT_CHECK( !gp );
255 CPPUNIT_CHECK( !m.extract_with(other_item(nKey), other_less() ));
256 CPPUNIT_CHECK( gp.empty());
258 CPPUNIT_ASSERT( m.empty() );
274 typedef typename Map::gc rcu;
275 typedef typename Map::rcu_lock rcu_lock;
276 typedef typename Map::value_type value_type;
277 typename Map::exempt_ptr ep;
279 static size_t const nLimit = 100;
281 for ( size_t i = 0; i < nLimit; ++i )
283 shuffle( arr, arr + nLimit );
285 for ( size_t i = 0; i < nLimit; ++i )
286 CPPUNIT_ASSERT( m.insert( arr[i], arr[i] ));
288 for ( size_t i = 0; i < nLimit; i += 2 ) {
293 pVal = m.get( nKey );
294 CPPUNIT_ASSERT( pVal != nullptr );
295 CPPUNIT_CHECK( pVal->first == nKey );
296 CPPUNIT_CHECK( pVal->second.m_val == nKey );
298 ep = m.extract( nKey );
299 CPPUNIT_ASSERT( ep );
300 CPPUNIT_ASSERT( !ep.empty() );
301 CPPUNIT_CHECK( pVal->first == ep->first );
302 CPPUNIT_CHECK( pVal->second.m_val == ep->second.m_val );
307 CPPUNIT_CHECK( m.get( nKey ) == nullptr );
308 ep = m.extract( nKey );
309 CPPUNIT_CHECK( !ep );
310 CPPUNIT_CHECK( ep.empty() );
313 pVal = m.get_with( other_item(nKey), other_less() );
314 CPPUNIT_ASSERT( pVal != nullptr );
315 CPPUNIT_CHECK( pVal->first == nKey );
316 CPPUNIT_CHECK( pVal->second.m_val == nKey );
318 ep = m.extract_with( other_item( nKey ), other_less() );
319 CPPUNIT_ASSERT( ep );
320 CPPUNIT_ASSERT( !ep.empty() );
321 CPPUNIT_CHECK( pVal->first == ep->first );
322 CPPUNIT_CHECK( pVal->second.m_val == (*ep).second.m_val );
327 CPPUNIT_CHECK( m.get_with( other_item(nKey), other_less() ) == nullptr );
328 CPPUNIT_CHECK( !m.extract_with( other_item(nKey), other_less() ));
329 CPPUNIT_CHECK( ep.empty() );
332 CPPUNIT_CHECK( m.empty() );
333 CPPUNIT_CHECK( check_size( m, 0 ));
336 CPPUNIT_CHECK( m.get( int(nLimit / 2) ) == nullptr );
337 ep = m.extract( int( nLimit / 2 ) );
338 CPPUNIT_CHECK( !ep );
339 CPPUNIT_CHECK( ep.empty() );
348 void test_rcu_michael_list()
356 typedef typename Map::gc rcu;
357 typedef typename Map::rcu_lock rcu_lock;
358 typedef typename Map::value_type value_type;
359 typename Map::exempt_ptr ep;
360 typename Map::raw_ptr gp;
362 static size_t const nLimit = 100;
364 for ( size_t i = 0; i < nLimit; ++i )
366 shuffle( arr, arr + nLimit );
368 for ( size_t i = 0; i < nLimit; ++i )
369 CPPUNIT_ASSERT( m.insert( arr[i], arr[i] ));
371 for ( size_t i = 0; i < nLimit; i += 2 ) {
376 CPPUNIT_ASSERT( gp );
377 CPPUNIT_CHECK( gp->first == nKey );
378 CPPUNIT_CHECK( gp->second.m_val == nKey );
382 ep = m.extract( nKey );
383 CPPUNIT_ASSERT( ep );
384 CPPUNIT_ASSERT( !ep.empty() );
385 CPPUNIT_CHECK( nKey == ep->first );
386 CPPUNIT_CHECK( nKey == ep->second.m_val );
391 CPPUNIT_CHECK( !m.get( nKey ));
393 ep = m.extract( nKey );
394 CPPUNIT_CHECK( !ep );
395 CPPUNIT_CHECK( ep.empty() );
400 gp = m.get_with( other_item(nKey), other_less() );
401 CPPUNIT_ASSERT( gp );
402 CPPUNIT_CHECK( gp->first == nKey );
403 CPPUNIT_CHECK( gp->second.m_val == nKey );
407 ep = m.extract_with( other_item( nKey ), other_less() );
408 CPPUNIT_ASSERT( ep );
409 CPPUNIT_ASSERT( !ep.empty() );
410 CPPUNIT_CHECK( nKey == ep->first );
411 CPPUNIT_CHECK( nKey == (*ep).second.m_val );
416 CPPUNIT_CHECK( !m.get_with( other_item(nKey), other_less() ));
418 CPPUNIT_CHECK( !m.extract_with( other_item(nKey), other_less() ));
419 CPPUNIT_CHECK( ep.empty() );
421 CPPUNIT_CHECK( m.empty() );
422 CPPUNIT_CHECK( check_size( m, 0 ));
425 CPPUNIT_CHECK( !m.get( int(nLimit / 2) ));
427 ep = m.extract( int( nLimit / 2 ) );
428 CPPUNIT_CHECK( !ep );
429 CPPUNIT_CHECK( ep.empty() );
437 void test_rcu_split_list()
439 test_rcu_michael_list<Map>();
443 void test_int_with( Map& m )
445 std::pair<bool, bool> ensureResult;
448 CPPUNIT_ASSERT( m.empty() );
449 CPPUNIT_ASSERT( check_size( m, 0 ));
450 CPPUNIT_ASSERT( !m.find(25) );
451 CPPUNIT_ASSERT( m.insert( 25 ) ) ; // value = 0
452 CPPUNIT_ASSERT( m.find(25) );
453 CPPUNIT_ASSERT( !m.empty() );
454 CPPUNIT_ASSERT( check_size( m, 1 ));
455 CPPUNIT_ASSERT( m.find(25) );
457 CPPUNIT_ASSERT( !m.insert( 25 ) );
458 CPPUNIT_ASSERT( !m.empty() );
459 CPPUNIT_ASSERT( check_size( m, 1 ));
461 CPPUNIT_ASSERT( !m.find_with(10, less()) );
462 CPPUNIT_ASSERT( m.insert( 10, 10 ) );
463 CPPUNIT_ASSERT( !m.empty() );
464 CPPUNIT_ASSERT( check_size( m, 2 ));
465 CPPUNIT_ASSERT( m.find_with(10, less()) );
467 CPPUNIT_ASSERT( !m.insert( 10, 20 ) );
468 CPPUNIT_ASSERT( !m.empty() );
469 CPPUNIT_ASSERT( check_size( m, 2 ));
471 CPPUNIT_ASSERT( !m.find(30) );
472 CPPUNIT_ASSERT( m.insert_with( 30, insert_functor<Map>() ) ) ; // value = 90
473 CPPUNIT_ASSERT( !m.empty() );
474 CPPUNIT_ASSERT( check_size( m, 3 ));
475 CPPUNIT_ASSERT( m.find(30) );
477 CPPUNIT_ASSERT( !m.insert_with( 10, insert_functor<Map>() ) );
478 CPPUNIT_ASSERT( !m.insert_with( 25, insert_functor<Map>() ) );
479 CPPUNIT_ASSERT( !m.insert_with( 30, insert_functor<Map>() ) );
482 CPPUNIT_ASSERT( !m.find(27) );
483 ensureResult = m.ensure( 27, insert_functor<Map>() ) ; // value = 54
484 CPPUNIT_ASSERT( ensureResult.first );
485 CPPUNIT_ASSERT( ensureResult.second );
486 CPPUNIT_ASSERT( m.find(27) );
490 CPPUNIT_ASSERT( m.find( 10, std::ref(chk) ));
492 CPPUNIT_ASSERT( m.find_with( 25, less(), std::ref( chk ) ) );
493 chk.m_nExpected = 90;
494 CPPUNIT_ASSERT( m.find( 30, std::ref( chk ) ) );
495 chk.m_nExpected = 54;
496 CPPUNIT_ASSERT( m.find( 27, std::ref( chk ) ) );
498 ensureResult = m.ensure( 10, insert_functor<Map>() ) ; // value = 50
499 CPPUNIT_ASSERT( ensureResult.first );
500 CPPUNIT_ASSERT( !ensureResult.second );
501 chk.m_nExpected = 50;
502 CPPUNIT_ASSERT( m.find( 10, std::ref( chk ) ) );
505 CPPUNIT_ASSERT( !m.find(100) );
506 CPPUNIT_ASSERT( !m.erase( 100 )) ; // not found
508 CPPUNIT_ASSERT( m.find(25) );
509 CPPUNIT_ASSERT( check_size( m, 4 ));
510 CPPUNIT_ASSERT( m.erase( 25 ));
511 CPPUNIT_ASSERT( !m.empty() );
512 CPPUNIT_ASSERT( check_size( m, 3 ));
513 CPPUNIT_ASSERT( !m.find(25) );
514 CPPUNIT_ASSERT( !m.erase( 25 ));
516 CPPUNIT_ASSERT( !m.find(258) );
517 CPPUNIT_ASSERT( m.insert(258))
518 CPPUNIT_ASSERT( check_size( m, 4 ));
519 CPPUNIT_ASSERT( m.find_with(258, less()) );
520 CPPUNIT_ASSERT( m.erase_with( 258, less() ));
521 CPPUNIT_ASSERT( !m.empty() );
522 CPPUNIT_ASSERT( check_size( m, 3 ));
523 CPPUNIT_ASSERT( !m.find(258) );
524 CPPUNIT_ASSERT( !m.erase_with( 258, less() ));
530 CPPUNIT_ASSERT( !m.find(29) );
531 CPPUNIT_ASSERT( m.insert(29, 290));
532 CPPUNIT_ASSERT( check_size( m, 4 ));
533 CPPUNIT_ASSERT( m.erase_with( 29, less(), std::ref( ext ) ) );
534 CPPUNIT_ASSERT( !m.empty() );
535 CPPUNIT_ASSERT( check_size( m, 3 ));
536 CPPUNIT_ASSERT( nVal == 290 );
538 CPPUNIT_ASSERT( !m.erase_with( 29, less(), std::ref( ext ) ) );
539 CPPUNIT_ASSERT( nVal == -1 );
541 CPPUNIT_ASSERT( m.erase( 30, std::ref( ext ) ) );
542 CPPUNIT_ASSERT( !m.empty() );
543 CPPUNIT_ASSERT( check_size( m, 2 ));
544 CPPUNIT_ASSERT( nVal == 90 );
546 CPPUNIT_ASSERT( !m.erase( 30, std::ref( ext ) ) );
547 CPPUNIT_ASSERT( nVal == -1 );
550 CPPUNIT_ASSERT( m.empty() );
551 CPPUNIT_ASSERT( check_size( m, 0 ));
554 CPPUNIT_ASSERT( m.emplace(126) ) ; // key = 126, val = 0
555 CPPUNIT_ASSERT( m.emplace(137, 731)) ; // key = 137, val = 731
556 CPPUNIT_ASSERT( m.emplace( 149, value_type(941) )) ; // key = 149, val = 941
558 CPPUNIT_ASSERT( !m.empty() );
559 CPPUNIT_ASSERT( check_size( m, 3 ));
562 CPPUNIT_ASSERT( m.find( 126, std::ref(chk) ));
563 chk.m_nExpected = 731;
564 CPPUNIT_ASSERT( m.find_with( 137, less(), std::ref(chk) ));
565 chk.m_nExpected = 941;
566 CPPUNIT_ASSERT( m.find( 149, std::ref(chk) ));
568 CPPUNIT_ASSERT( !m.emplace(126, 621)) ; // already in map
570 CPPUNIT_ASSERT( m.find( 126, std::ref(chk) ));
571 CPPUNIT_ASSERT( !m.empty() );
572 CPPUNIT_ASSERT( check_size( m, 3 ));
575 CPPUNIT_ASSERT( m.empty() );
576 CPPUNIT_ASSERT( check_size( m, 0 ));
583 typedef typename Map::iterator iterator;
584 typedef typename Map::const_iterator const_iterator;
589 CPPUNIT_ASSERT( m.empty() );
590 CPPUNIT_ASSERT( check_size( m, 0 ));
592 CPPUNIT_ASSERT( m.find(10) == m.end() );
593 iterator it = m.insert( 10 );
594 CPPUNIT_ASSERT( it != m.end() );
595 CPPUNIT_ASSERT( !m.empty() );
596 CPPUNIT_ASSERT( check_size( m, 1 ));
597 CPPUNIT_ASSERT( m.find(10) == it );
598 CPPUNIT_ASSERT( it->first == 10 );
599 CPPUNIT_ASSERT( it->second.m_val == 0 );
601 CPPUNIT_ASSERT( m.find(100) == m.end() );
602 it = m.insert( 100, 200 );
603 CPPUNIT_ASSERT( it != m.end() );
604 CPPUNIT_ASSERT( !m.empty() );
605 CPPUNIT_ASSERT( check_size( m, 2 ));
606 CPPUNIT_ASSERT( m.find_with(100, less()) == it );
607 CPPUNIT_ASSERT( it->first == 100 );
608 CPPUNIT_ASSERT( it->second.m_val == 200 );
610 CPPUNIT_ASSERT( m.find(55) == m.end() );
611 it = m.insert_with( 55, insert_functor<Map>() );
612 CPPUNIT_ASSERT( it != m.end() );
613 CPPUNIT_ASSERT( !m.empty() );
614 CPPUNIT_ASSERT( check_size( m, 3 ));
615 CPPUNIT_ASSERT( m.find(55) == it );
616 CPPUNIT_ASSERT( it->first == 55 );
617 CPPUNIT_ASSERT( it->second.m_val == 55 * 3 );
619 CPPUNIT_ASSERT( m.insert( 55 ) == m.end() );
620 CPPUNIT_ASSERT( m.insert( 55, 10 ) == m.end() );
621 CPPUNIT_ASSERT( m.insert_with( 55, insert_functor<Map>()) == m.end() );
623 CPPUNIT_ASSERT( m.find(10) != m.end() );
624 std::pair<iterator, bool> ensureResult = m.ensure( 10 );
625 CPPUNIT_ASSERT( ensureResult.first != m.end() );
626 CPPUNIT_ASSERT( !ensureResult.second );
627 CPPUNIT_ASSERT( !m.empty() );
628 ensureResult.first->second.m_val = ensureResult.first->first * 5;
629 CPPUNIT_ASSERT( check_size( m, 3 ));
630 CPPUNIT_ASSERT( m.find(10) == ensureResult.first );
632 CPPUNIT_ASSERT( it != m.end() );
633 CPPUNIT_ASSERT( it->second.m_val == 50 );
635 CPPUNIT_ASSERT( m.find(120) == m.end() );
636 ensureResult = m.ensure( 120 );
637 CPPUNIT_ASSERT( ensureResult.first != m.end() );
638 CPPUNIT_ASSERT( ensureResult.second );
639 CPPUNIT_ASSERT( !m.empty() );
640 CPPUNIT_ASSERT( check_size( m, 4 ));
641 ensureResult.first->second.m_val = ensureResult.first->first * 5;
642 CPPUNIT_ASSERT( m.find_with(120, less()) == ensureResult.first );
643 it = m.find_with(120, less());
644 CPPUNIT_ASSERT( it != m.end() );
645 CPPUNIT_ASSERT( it->second.m_val == 120 * 5 );
646 CPPUNIT_ASSERT( m.find_with(120, less()) == m.find(120) );
649 it = m.emplace( 151 ) ; // key = 151, val = 0
650 CPPUNIT_ASSERT( it != m.end() );
651 CPPUNIT_ASSERT( it->first == 151 );
652 CPPUNIT_ASSERT( it->second.m_val == 0 );
654 it = m.emplace( 174, 471 ) ; // key == 174, val = 471
655 CPPUNIT_ASSERT( it != m.end() );
656 CPPUNIT_ASSERT( it->first == 174 );
657 CPPUNIT_ASSERT( it->second.m_val == 471 );
659 it = m.emplace( 190, value_type(91)) ; // key == 190, val = 19
660 CPPUNIT_ASSERT( it != m.end() );
661 CPPUNIT_ASSERT( it->first == 190 );
662 CPPUNIT_ASSERT( it->second.m_val == 91 );
664 it = m.emplace( 151, 1051 );
665 CPPUNIT_ASSERT( it == m.end());
668 CPPUNIT_ASSERT( it != m.end() );
669 CPPUNIT_ASSERT( it->first == 174 );
670 CPPUNIT_ASSERT( it->second.m_val == 471 );
673 CPPUNIT_ASSERT( it != m.end() );
674 CPPUNIT_ASSERT( it->first == 190 );
675 CPPUNIT_ASSERT( it->second.m_val == 91 );
678 CPPUNIT_ASSERT( it != m.end() );
679 CPPUNIT_ASSERT( it->first == 151 );
680 CPPUNIT_ASSERT( it->second.m_val == 0 );
688 for ( int i = 0; i < 500; ++i ) {
689 CPPUNIT_ASSERT( m.insert( i, i * 2 ) != m.end() );
691 CPPUNIT_ASSERT( check_size( m, 500 ));
694 typename Map::iterator it( m.begin() );
695 typename Map::const_iterator cit( m.cbegin() );
696 CPPUNIT_CHECK( it == cit );
697 CPPUNIT_CHECK( it != m.end() );
698 CPPUNIT_CHECK( it != m.cend() );
699 CPPUNIT_CHECK( cit != m.end() );
700 CPPUNIT_CHECK( cit != m.cend() );
702 CPPUNIT_CHECK( it != cit );
703 CPPUNIT_CHECK( it != m.end() );
704 CPPUNIT_CHECK( it != m.cend() );
705 CPPUNIT_CHECK( cit != m.end() );
706 CPPUNIT_CHECK( cit != m.cend() );
708 CPPUNIT_CHECK( it == cit );
709 CPPUNIT_CHECK( it != m.end() );
710 CPPUNIT_CHECK( it != m.cend() );
711 CPPUNIT_CHECK( cit != m.end() );
712 CPPUNIT_CHECK( cit != m.cend() );
716 for ( iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) {
718 CPPUNIT_CHECK( it2 == it );
719 CPPUNIT_CHECK( it2 != itEnd );
720 CPPUNIT_ASSERT( it->first * 2 == (*it).second.m_val );
721 it->second = it->first;
724 Map const& refMap = m;
725 for ( const_iterator it = refMap.begin(), itEnd = refMap.end(); it != itEnd; ++it ) {
726 CPPUNIT_ASSERT( it->first == it->second.m_val );
727 CPPUNIT_ASSERT( (*it).first == (*it).second.m_val );
733 void test_int_nogc_unordered()
735 typedef typename Map::iterator iterator;
736 typedef typename Map::const_iterator const_iterator;
741 CPPUNIT_ASSERT( m.empty() );
742 CPPUNIT_ASSERT( check_size( m, 0 ));
744 CPPUNIT_ASSERT( m.find(10) == m.end() );
745 iterator it = m.insert( 10 );
746 CPPUNIT_ASSERT( it != m.end() );
747 CPPUNIT_ASSERT( !m.empty() );
748 CPPUNIT_ASSERT( check_size( m, 1 ));
749 CPPUNIT_ASSERT( m.find(10) == it );
750 CPPUNIT_ASSERT( it->first == 10 );
751 CPPUNIT_ASSERT( it->second.m_val == 0 );
753 CPPUNIT_ASSERT( m.find(100) == m.end() );
754 it = m.insert( 100, 200 );
755 CPPUNIT_ASSERT( it != m.end() );
756 CPPUNIT_ASSERT( !m.empty() );
757 CPPUNIT_ASSERT( check_size( m, 2 ));
758 CPPUNIT_ASSERT( m.find_with(100, equal()) == it );
759 CPPUNIT_ASSERT( it->first == 100 );
760 CPPUNIT_ASSERT( it->second.m_val == 200 );
762 CPPUNIT_ASSERT( m.find(55) == m.end() );
763 it = m.insert_with( 55, insert_functor<Map>() );
764 CPPUNIT_ASSERT( it != m.end() );
765 CPPUNIT_ASSERT( !m.empty() );
766 CPPUNIT_ASSERT( check_size( m, 3 ));
767 CPPUNIT_ASSERT( m.find(55) == it );
768 CPPUNIT_ASSERT( it->first == 55 );
769 CPPUNIT_ASSERT( it->second.m_val == 55 * 3 );
771 CPPUNIT_ASSERT( m.insert( 55 ) == m.end() );
772 CPPUNIT_ASSERT( m.insert( 55, 10 ) == m.end() );
773 CPPUNIT_ASSERT( m.insert_with( 55, insert_functor<Map>()) == m.end() );
775 CPPUNIT_ASSERT( m.find(10) != m.end() );
776 std::pair<iterator, bool> ensureResult = m.ensure( 10 );
777 CPPUNIT_ASSERT( ensureResult.first != m.end() );
778 CPPUNIT_ASSERT( !ensureResult.second );
779 CPPUNIT_ASSERT( !m.empty() );
780 ensureResult.first->second.m_val = ensureResult.first->first * 5;
781 CPPUNIT_ASSERT( check_size( m, 3 ));
782 CPPUNIT_ASSERT( m.find(10) == ensureResult.first );
784 CPPUNIT_ASSERT( it != m.end() );
785 CPPUNIT_ASSERT( it->second.m_val == 50 );
787 CPPUNIT_ASSERT( m.find(120) == m.end() );
788 ensureResult = m.ensure( 120 );
789 CPPUNIT_ASSERT( ensureResult.first != m.end() );
790 CPPUNIT_ASSERT( ensureResult.second );
791 CPPUNIT_ASSERT( !m.empty() );
792 CPPUNIT_ASSERT( check_size( m, 4 ));
793 ensureResult.first->second.m_val = ensureResult.first->first * 5;
794 CPPUNIT_ASSERT( m.find_with(120, equal()) == ensureResult.first );
795 it = m.find_with(120, equal());
796 CPPUNIT_ASSERT( it != m.end() );
797 CPPUNIT_ASSERT( it->second.m_val == 120 * 5 );
798 CPPUNIT_ASSERT( m.find_with(120, equal()) == m.find(120) );
801 it = m.emplace( 151 ) ; // key = 151, val = 0
802 CPPUNIT_ASSERT( it != m.end() );
803 CPPUNIT_ASSERT( it->first == 151 );
804 CPPUNIT_ASSERT( it->second.m_val == 0 );
806 it = m.emplace( 174, 471 ) ; // key == 174, val = 471
807 CPPUNIT_ASSERT( it != m.end() );
808 CPPUNIT_ASSERT( it->first == 174 );
809 CPPUNIT_ASSERT( it->second.m_val == 471 );
811 it = m.emplace( 190, value_type(91)) ; // key == 190, val = 19
812 CPPUNIT_ASSERT( it != m.end() );
813 CPPUNIT_ASSERT( it->first == 190 );
814 CPPUNIT_ASSERT( it->second.m_val == 91 );
816 it = m.emplace( 151, 1051 );
817 CPPUNIT_ASSERT( it == m.end());
820 CPPUNIT_ASSERT( it != m.end() );
821 CPPUNIT_ASSERT( it->first == 174 );
822 CPPUNIT_ASSERT( it->second.m_val == 471 );
825 CPPUNIT_ASSERT( it != m.end() );
826 CPPUNIT_ASSERT( it->first == 190 );
827 CPPUNIT_ASSERT( it->second.m_val == 91 );
830 CPPUNIT_ASSERT( it != m.end() );
831 CPPUNIT_ASSERT( it->first == 151 );
832 CPPUNIT_ASSERT( it->second.m_val == 0 );
840 for ( int i = 0; i < 500; ++i ) {
841 CPPUNIT_ASSERT( m.insert( i, i * 2 ) != m.end() );
843 CPPUNIT_ASSERT( check_size( m, 500 ));
846 typename Map::iterator it( m.begin() );
847 typename Map::const_iterator cit( m.cbegin() );
848 CPPUNIT_CHECK( it == cit );
849 CPPUNIT_CHECK( it != m.end() );
850 CPPUNIT_CHECK( it != m.cend() );
851 CPPUNIT_CHECK( cit != m.end() );
852 CPPUNIT_CHECK( cit != m.cend() );
854 CPPUNIT_CHECK( it != cit );
855 CPPUNIT_CHECK( it != m.end() );
856 CPPUNIT_CHECK( it != m.cend() );
857 CPPUNIT_CHECK( cit != m.end() );
858 CPPUNIT_CHECK( cit != m.cend() );
860 CPPUNIT_CHECK( it == cit );
861 CPPUNIT_CHECK( it != m.end() );
862 CPPUNIT_CHECK( it != m.cend() );
863 CPPUNIT_CHECK( cit != m.end() );
864 CPPUNIT_CHECK( cit != m.cend() );
868 for ( iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) {
870 CPPUNIT_CHECK( it2 == it );
871 CPPUNIT_CHECK( it2 != itEnd );
872 CPPUNIT_ASSERT( it->first * 2 == (*it).second.m_val );
873 it->second = it->first;
876 Map const& refMap = m;
877 for ( const_iterator it = refMap.begin(), itEnd = refMap.end(); it != itEnd; ++it ) {
878 CPPUNIT_ASSERT( it->first == it->second.m_val );
879 CPPUNIT_ASSERT( (*it).first == (*it).second.m_val );
887 typedef typename Map::iterator iterator;
888 typedef typename Map::const_iterator const_iterator;
892 const int nMaxCount = 500;
893 for ( int i = 0; i < nMaxCount; ++i ) {
894 CPPUNIT_ASSERT( s.insert( i, i * 2 ));
898 typename Map::iterator it( s.begin() );
899 typename Map::const_iterator cit( s.cbegin() );
900 CPPUNIT_CHECK( it == cit );
901 CPPUNIT_CHECK( it != s.end() );
902 CPPUNIT_CHECK( it != s.cend() );
903 CPPUNIT_CHECK( cit != s.end() );
904 CPPUNIT_CHECK( cit != s.cend() );
906 CPPUNIT_CHECK( it != cit );
907 CPPUNIT_CHECK( it != s.end() );
908 CPPUNIT_CHECK( it != s.cend() );
909 CPPUNIT_CHECK( cit != s.end() );
910 CPPUNIT_CHECK( cit != s.cend() );
912 CPPUNIT_CHECK( it == cit );
913 CPPUNIT_CHECK( it != s.end() );
914 CPPUNIT_CHECK( it != s.cend() );
915 CPPUNIT_CHECK( cit != s.end() );
916 CPPUNIT_CHECK( cit != s.cend() );
920 for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
921 CPPUNIT_ASSERT( it->first * 2 == it->second.m_val );
922 CPPUNIT_ASSERT( (*it).first * 2 == (*it).second.m_val );
923 it->second.m_val = it->first;
926 CPPUNIT_ASSERT( nCount == nMaxCount );
928 Map const& refSet = s;
930 for ( const_iterator it = refSet.begin(), itEnd = refSet.end(); it != itEnd; ++it ) {
931 CPPUNIT_ASSERT( it->first == it->second.m_val );
932 CPPUNIT_ASSERT( (*it).first == (*it).second.m_val );
935 CPPUNIT_ASSERT( nCount == nMaxCount );
939 void Michael_HP_cmp();
940 void Michael_HP_less();
941 void Michael_HP_cmpmix();
943 void Michael_DHP_cmp();
944 void Michael_DHP_less();
945 void Michael_DHP_cmpmix();
947 void Michael_RCU_GPI_cmp();
948 void Michael_RCU_GPI_less();
949 void Michael_RCU_GPI_cmpmix();
951 void Michael_RCU_GPB_cmp();
952 void Michael_RCU_GPB_less();
953 void Michael_RCU_GPB_cmpmix();
955 void Michael_RCU_GPT_cmp();
956 void Michael_RCU_GPT_less();
957 void Michael_RCU_GPT_cmpmix();
959 void Michael_RCU_SHB_cmp();
960 void Michael_RCU_SHB_less();
961 void Michael_RCU_SHB_cmpmix();
963 void Michael_RCU_SHT_cmp();
964 void Michael_RCU_SHT_less();
965 void Michael_RCU_SHT_cmpmix();
967 void Michael_nogc_cmp();
968 void Michael_nogc_less();
969 void Michael_nogc_cmpmix();
973 void Lazy_HP_cmpmix();
976 void Lazy_DHP_less();
977 void Lazy_DHP_cmpmix();
979 void Lazy_RCU_GPI_cmp();
980 void Lazy_RCU_GPI_less();
981 void Lazy_RCU_GPI_cmpmix();
983 void Lazy_RCU_GPB_cmp();
984 void Lazy_RCU_GPB_less();
985 void Lazy_RCU_GPB_cmpmix();
987 void Lazy_RCU_GPT_cmp();
988 void Lazy_RCU_GPT_less();
989 void Lazy_RCU_GPT_cmpmix();
991 void Lazy_RCU_SHB_cmp();
992 void Lazy_RCU_SHB_less();
993 void Lazy_RCU_SHB_cmpmix();
995 void Lazy_RCU_SHT_cmp();
996 void Lazy_RCU_SHT_less();
997 void Lazy_RCU_SHT_cmpmix();
999 void Lazy_nogc_cmp();
1000 void Lazy_nogc_less();
1001 void Lazy_nogc_equal();
1002 void Lazy_nogc_cmpmix();
1004 void Split_HP_cmp();
1005 void Split_HP_less();
1006 void Split_HP_cmpmix();
1007 void Split_HP_cmpmix_stat();
1009 void Split_DHP_cmp();
1010 void Split_DHP_less();
1011 void Split_DHP_cmpmix();
1012 void Split_DHP_cmpmix_stat();
1014 void Split_RCU_GPI_cmp();
1015 void Split_RCU_GPI_less();
1016 void Split_RCU_GPI_cmpmix();
1017 void Split_RCU_GPI_cmpmix_stat();
1019 void Split_RCU_GPB_cmp();
1020 void Split_RCU_GPB_less();
1021 void Split_RCU_GPB_cmpmix();
1022 void Split_RCU_GPB_cmpmix_stat();
1024 void Split_RCU_GPT_cmp();
1025 void Split_RCU_GPT_less();
1026 void Split_RCU_GPT_cmpmix();
1027 void Split_RCU_GPT_cmpmix_stat();
1029 void Split_RCU_SHB_cmp();
1030 void Split_RCU_SHB_less();
1031 void Split_RCU_SHB_cmpmix();
1032 void Split_RCU_SHB_cmpmix_stat();
1034 void Split_RCU_SHT_cmp();
1035 void Split_RCU_SHT_less();
1036 void Split_RCU_SHT_cmpmix();
1037 void Split_RCU_SHT_cmpmix_stat();
1039 void Split_nogc_cmp();
1040 void Split_nogc_less();
1041 void Split_nogc_cmpmix();
1042 void Split_nogc_cmpmix_stat();
1044 void Split_Lazy_HP_cmp();
1045 void Split_Lazy_HP_less();
1046 void Split_Lazy_HP_cmpmix();
1047 void Split_Lazy_HP_cmpmix_stat();
1049 void Split_Lazy_DHP_cmp();
1050 void Split_Lazy_DHP_less();
1051 void Split_Lazy_DHP_cmpmix();
1052 void Split_Lazy_DHP_cmpmix_stat();
1054 void Split_Lazy_RCU_GPI_cmp();
1055 void Split_Lazy_RCU_GPI_less();
1056 void Split_Lazy_RCU_GPI_cmpmix();
1057 void Split_Lazy_RCU_GPI_cmpmix_stat();
1059 void Split_Lazy_RCU_GPB_cmp();
1060 void Split_Lazy_RCU_GPB_less();
1061 void Split_Lazy_RCU_GPB_cmpmix();
1062 void Split_Lazy_RCU_GPB_cmpmix_stat();
1064 void Split_Lazy_RCU_GPT_cmp();
1065 void Split_Lazy_RCU_GPT_less();
1066 void Split_Lazy_RCU_GPT_cmpmix();
1067 void Split_Lazy_RCU_GPT_cmpmix_stat();
1069 void Split_Lazy_RCU_SHB_cmp();
1070 void Split_Lazy_RCU_SHB_less();
1071 void Split_Lazy_RCU_SHB_cmpmix();
1072 void Split_Lazy_RCU_SHB_cmpmix_stat();
1074 void Split_Lazy_RCU_SHT_cmp();
1075 void Split_Lazy_RCU_SHT_less();
1076 void Split_Lazy_RCU_SHT_cmpmix();
1077 void Split_Lazy_RCU_SHT_cmpmix_stat();
1079 void Split_Lazy_nogc_cmp();
1080 void Split_Lazy_nogc_less();
1081 void Split_Lazy_nogc_cmpmix();
1082 void Split_Lazy_nogc_cmpmix_stat();
1084 CPPUNIT_TEST_SUITE(HashMapHdrTest)
1085 CPPUNIT_TEST(Michael_HP_cmp)
1086 CPPUNIT_TEST(Michael_HP_less)
1087 CPPUNIT_TEST(Michael_HP_cmpmix)
1089 CPPUNIT_TEST(Michael_DHP_cmp)
1090 CPPUNIT_TEST(Michael_DHP_less)
1091 CPPUNIT_TEST(Michael_DHP_cmpmix)
1093 CPPUNIT_TEST(Michael_RCU_GPI_cmp)
1094 CPPUNIT_TEST(Michael_RCU_GPI_less)
1095 CPPUNIT_TEST(Michael_RCU_GPI_cmpmix)
1097 CPPUNIT_TEST(Michael_RCU_GPB_cmp)
1098 CPPUNIT_TEST(Michael_RCU_GPB_less)
1099 CPPUNIT_TEST(Michael_RCU_GPB_cmpmix)
1101 CPPUNIT_TEST(Michael_RCU_SHT_cmp)
1102 CPPUNIT_TEST(Michael_RCU_SHT_less)
1103 CPPUNIT_TEST(Michael_RCU_SHT_cmpmix)
1105 CPPUNIT_TEST(Michael_RCU_SHB_cmp)
1106 CPPUNIT_TEST(Michael_RCU_SHB_less)
1107 CPPUNIT_TEST(Michael_RCU_SHB_cmpmix)
1109 CPPUNIT_TEST(Michael_RCU_GPT_cmp)
1110 CPPUNIT_TEST(Michael_RCU_GPT_less)
1111 CPPUNIT_TEST(Michael_RCU_GPT_cmpmix)
1113 CPPUNIT_TEST(Michael_nogc_cmp)
1114 CPPUNIT_TEST(Michael_nogc_less)
1115 CPPUNIT_TEST(Michael_nogc_cmpmix)
1117 CPPUNIT_TEST(Lazy_HP_cmp)
1118 CPPUNIT_TEST(Lazy_HP_less)
1119 CPPUNIT_TEST(Lazy_HP_cmpmix)
1121 CPPUNIT_TEST(Lazy_DHP_cmp)
1122 CPPUNIT_TEST(Lazy_DHP_less)
1123 CPPUNIT_TEST(Lazy_DHP_cmpmix)
1125 CPPUNIT_TEST(Lazy_RCU_GPI_cmp)
1126 CPPUNIT_TEST(Lazy_RCU_GPI_less)
1127 CPPUNIT_TEST(Lazy_RCU_GPI_cmpmix)
1129 CPPUNIT_TEST(Lazy_RCU_GPB_cmp)
1130 CPPUNIT_TEST(Lazy_RCU_GPB_less)
1131 CPPUNIT_TEST(Lazy_RCU_GPB_cmpmix)
1133 CPPUNIT_TEST(Lazy_RCU_GPT_cmp)
1134 CPPUNIT_TEST(Lazy_RCU_GPT_less)
1135 CPPUNIT_TEST(Lazy_RCU_GPT_cmpmix)
1137 CPPUNIT_TEST(Lazy_RCU_SHB_cmp)
1138 CPPUNIT_TEST(Lazy_RCU_SHB_less)
1139 CPPUNIT_TEST(Lazy_RCU_SHB_cmpmix)
1141 CPPUNIT_TEST(Lazy_RCU_SHT_cmp)
1142 CPPUNIT_TEST(Lazy_RCU_SHT_less)
1143 CPPUNIT_TEST(Lazy_RCU_SHT_cmpmix)
1145 CPPUNIT_TEST(Lazy_nogc_cmp)
1146 CPPUNIT_TEST(Lazy_nogc_less)
1147 CPPUNIT_TEST(Lazy_nogc_equal)
1148 CPPUNIT_TEST(Lazy_nogc_cmpmix)
1150 CPPUNIT_TEST(Split_HP_cmp)
1151 CPPUNIT_TEST(Split_HP_less)
1152 CPPUNIT_TEST(Split_HP_cmpmix)
1153 CPPUNIT_TEST( Split_HP_cmpmix_stat )
1155 CPPUNIT_TEST(Split_DHP_cmp)
1156 CPPUNIT_TEST(Split_DHP_less)
1157 CPPUNIT_TEST(Split_DHP_cmpmix)
1158 CPPUNIT_TEST( Split_DHP_cmpmix_stat )
1160 CPPUNIT_TEST(Split_RCU_GPI_cmp)
1161 CPPUNIT_TEST(Split_RCU_GPI_less)
1162 CPPUNIT_TEST(Split_RCU_GPI_cmpmix)
1163 CPPUNIT_TEST( Split_RCU_GPI_cmpmix_stat )
1165 CPPUNIT_TEST(Split_RCU_GPB_cmp)
1166 CPPUNIT_TEST(Split_RCU_GPB_less)
1167 CPPUNIT_TEST(Split_RCU_GPB_cmpmix)
1168 CPPUNIT_TEST( Split_RCU_GPB_cmpmix_stat )
1170 CPPUNIT_TEST(Split_RCU_GPT_cmp)
1171 CPPUNIT_TEST(Split_RCU_GPT_less)
1172 CPPUNIT_TEST(Split_RCU_GPT_cmpmix)
1173 CPPUNIT_TEST( Split_RCU_GPT_cmpmix_stat )
1175 CPPUNIT_TEST(Split_RCU_SHB_cmp)
1176 CPPUNIT_TEST(Split_RCU_SHB_less)
1177 CPPUNIT_TEST(Split_RCU_SHB_cmpmix)
1178 CPPUNIT_TEST( Split_RCU_SHB_cmpmix_stat )
1180 CPPUNIT_TEST(Split_RCU_SHT_cmp)
1181 CPPUNIT_TEST(Split_RCU_SHT_less)
1182 CPPUNIT_TEST(Split_RCU_SHT_cmpmix)
1183 CPPUNIT_TEST( Split_RCU_SHT_cmpmix_stat )
1185 CPPUNIT_TEST(Split_nogc_cmp)
1186 CPPUNIT_TEST(Split_nogc_less)
1187 CPPUNIT_TEST(Split_nogc_cmpmix)
1188 CPPUNIT_TEST( Split_nogc_cmpmix_stat )
1190 CPPUNIT_TEST(Split_Lazy_HP_cmp)
1191 CPPUNIT_TEST(Split_Lazy_HP_less)
1192 CPPUNIT_TEST(Split_Lazy_HP_cmpmix)
1193 CPPUNIT_TEST( Split_Lazy_HP_cmpmix_stat )
1195 CPPUNIT_TEST(Split_Lazy_DHP_cmp)
1196 CPPUNIT_TEST(Split_Lazy_DHP_less)
1197 CPPUNIT_TEST(Split_Lazy_DHP_cmpmix)
1198 CPPUNIT_TEST( Split_Lazy_DHP_cmpmix_stat )
1200 CPPUNIT_TEST(Split_Lazy_RCU_GPI_cmp)
1201 CPPUNIT_TEST(Split_Lazy_RCU_GPI_less)
1202 CPPUNIT_TEST(Split_Lazy_RCU_GPI_cmpmix)
1203 CPPUNIT_TEST( Split_Lazy_RCU_GPI_cmpmix_stat )
1205 CPPUNIT_TEST(Split_Lazy_RCU_GPB_cmp)
1206 CPPUNIT_TEST(Split_Lazy_RCU_GPB_less)
1207 CPPUNIT_TEST(Split_Lazy_RCU_GPB_cmpmix)
1208 CPPUNIT_TEST( Split_Lazy_RCU_GPB_cmpmix_stat )
1210 CPPUNIT_TEST(Split_Lazy_RCU_GPT_cmp)
1211 CPPUNIT_TEST(Split_Lazy_RCU_GPT_less)
1212 CPPUNIT_TEST(Split_Lazy_RCU_GPT_cmpmix)
1213 CPPUNIT_TEST( Split_Lazy_RCU_GPT_cmpmix_stat )
1215 CPPUNIT_TEST(Split_Lazy_RCU_SHB_cmp)
1216 CPPUNIT_TEST(Split_Lazy_RCU_SHB_less)
1217 CPPUNIT_TEST(Split_Lazy_RCU_SHB_cmpmix)
1218 CPPUNIT_TEST( Split_Lazy_RCU_SHB_cmpmix_stat )
1220 CPPUNIT_TEST(Split_Lazy_RCU_SHT_cmp)
1221 CPPUNIT_TEST(Split_Lazy_RCU_SHT_less)
1222 CPPUNIT_TEST(Split_Lazy_RCU_SHT_cmpmix)
1223 CPPUNIT_TEST( Split_Lazy_RCU_SHT_cmpmix_stat )
1225 CPPUNIT_TEST(Split_Lazy_nogc_cmp)
1226 CPPUNIT_TEST(Split_Lazy_nogc_less)
1227 CPPUNIT_TEST(Split_Lazy_nogc_cmpmix)
1228 CPPUNIT_TEST( Split_Lazy_nogc_cmpmix_stat )
1229 CPPUNIT_TEST_SUITE_END()
1234 #endif // #ifndef CDSTEST_HDR_MAP_H