From 7cab33fa07a1f37cb50be2e695f1caaee51f8f18 Mon Sep 17 00:00:00 2001 From: Zbigniew Romanowski Date: Sat, 28 Oct 2017 12:51:00 +0200 Subject: [PATCH 1/2] Function count implemented --- src/bplustree.cpp | 7 +++++-- src/bplustree.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bplustree.cpp b/src/bplustree.cpp index 94ad218..f723c66 100644 --- a/src/bplustree.cpp +++ b/src/bplustree.cpp @@ -16,6 +16,7 @@ BPlusTree::BPlusTree( size_t order) : m_order{ order } , m_root{ nullptr } + , m_count( 0 ) { } @@ -51,8 +52,7 @@ Value BPlusTree::get( Key key ) // size_t BPlusTree::count() const { - assert( 0 ); - return 0; + return m_count; } // @@ -68,6 +68,7 @@ void BPlusTree::insert( Key key, Value value ) { insertIntoLeaf( key, value ); } + m_count++; } // @@ -153,6 +154,7 @@ void BPlusTree::remove(Key key) { removeFromLeaf( key ); } + m_count--; } // @@ -315,6 +317,7 @@ void BPlusTree::destroyTree() delete static_cast< InternalNode* >( m_root ); } m_root = nullptr; + m_count = 0; } diff --git a/src/bplustree.h b/src/bplustree.h index 7919c04..1c70afb 100644 --- a/src/bplustree.h +++ b/src/bplustree.h @@ -48,6 +48,8 @@ class BPlusTree private: const size_t m_order; Node* m_root; + + size_t m_count; }; #endif From ea309f7eb02bd724234e3fcac95c08e3d601bc86 Mon Sep 17 00:00:00 2001 From: Zbigniew Romanowski Date: Sat, 28 Oct 2017 12:51:15 +0200 Subject: [PATCH 2/2] Test extended --- src/main.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f023d6a..16faf7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,11 +71,10 @@ void Check() throw std::runtime_error( "Insert Error" ); } } - -// if( bPlusTree.count() != stlMap.size() ) -// { -// throw std::runtime_error( "Insert Error: Not equal size" ); -// } + if( bPlusTree.count() != stlMap.size() ) + { + throw std::runtime_error( "Insert Error: Not equal size" ); + } // Make key randomly distributed other then inserted std::shuffle( key.begin(), key.end(), std::mt19937{ std::random_device{}() } ); @@ -86,11 +85,10 @@ void Check() bPlusTree.remove( k ); stlMap.erase( k ); } - -// if( bPlusTree.count() != stlMap.size() ) -// { -// throw std::runtime_error( "Delete Error: Not equal size" ); -// } + if( bPlusTree.count() != stlMap.size() ) + { + throw std::runtime_error( "Delete Error: Not equal size" ); + } } //