Improved checking of internal consistency for BronsonAVLTree
authorkhizmax <libcds.dev@gmail.com>
Thu, 19 Mar 2015 21:30:01 +0000 (00:30 +0300)
committerkhizmax <libcds.dev@gmail.com>
Thu, 19 Mar 2015 21:30:01 +0000 (00:30 +0300)
cds/container/impl/bronson_avltree_map_rcu.h
tests/unit/map2/map_types.h

index 0439e7dfb6c7979e499abf5c7d9afcfdf9966d2a..775f63196174fd8feb676e501c2ca33884473549 100644 (file)
@@ -762,8 +762,16 @@ namespace cds { namespace container {
         size_t do_check_consistency( node_type * pNode, size_t nLevel, Func f, size_t& nErrors ) const
         {
             if ( pNode ) {
-                size_t hLeft = do_check_consistency( child( pNode, left_child, memory_model::memory_order_relaxed ), nLevel + 1, f, nErrors );
-                size_t hRight = do_check_consistency( child( pNode, right_child, memory_model::memory_order_relaxed ), nLevel + 1, f, nErrors );
+                key_comparator cmp;
+                node_type * pLeft = child( pNode, left_child, memory_model::memory_order_relaxed );
+                node_type * pRight = child( pNode, right_child, memory_model::memory_order_relaxed );
+                if ( pLeft && cmp( pLeft->m_key, pNode->m_key ) > 0 )
+                    ++nErrors;
+                if (  pRight && cmp( pNode->m_key, pRight->m_key ) > 0 )
+                    ++nErrors;
+
+                size_t hLeft = do_check_consistency( pLeft, nLevel + 1, f, nErrors );
+                size_t hRight = do_check_consistency( pRight, nLevel + 1, f, nErrors );
 
                 if ( hLeft >= hRight ) {
                     if ( hLeft - hRight > 1 ) {
index 4417b02827da5cd9ca537311c1904dfd5a4f8616..e898f82cb0c5230a7172552e3cb4a9f06ec3b5c7 100644 (file)
@@ -1938,10 +1938,11 @@ namespace map2 {
     static inline void check_before_cleanup( cc::BronsonAVLTreeMap<GC, Key, T, Traits>& m )
     {
         CPPUNIT_MSG( "  Check internal consistency (single-threaded)..." );
-        m.check_consistency([]( size_t nLevel, size_t hLeft, size_t hRight )
+        bool bOk = m.check_consistency([]( size_t nLevel, size_t hLeft, size_t hRight )
             { 
                 CPPUNIT_MSG( "Tree violation on level=" << nLevel << ": hLeft=" << hLeft << ", hRight=" << hRight ) 
             });
+        CPPUNIT_CHECK_CURRENT_EX( bOk, "check_consistency failed");
     }
 
     template <typename K, typename V, typename Traits>