Skip to content

Commit

Permalink
Merge pull request #12 from romz-pl/feature-count
Browse files Browse the repository at this point in the history
Feature count
  • Loading branch information
romz-pl authored Oct 28, 2017
2 parents a53a1e4 + ea309f7 commit dc2ea71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/bplustree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
BPlusTree::BPlusTree( size_t order)
: m_order{ order }
, m_root{ nullptr }
, m_count( 0 )
{

}
Expand Down Expand Up @@ -51,8 +52,7 @@ Value BPlusTree::get( Key key )
//
size_t BPlusTree::count() const
{
assert( 0 );
return 0;
return m_count;
}

//
Expand All @@ -68,6 +68,7 @@ void BPlusTree::insert( Key key, Value value )
{
insertIntoLeaf( key, value );
}
m_count++;
}

//
Expand Down Expand Up @@ -153,6 +154,7 @@ void BPlusTree::remove(Key key)
{
removeFromLeaf( key );
}
m_count--;
}

//
Expand Down Expand Up @@ -315,6 +317,7 @@ void BPlusTree::destroyTree()
delete static_cast< InternalNode* >( m_root );
}
m_root = nullptr;
m_count = 0;
}


Expand Down
2 changes: 2 additions & 0 deletions src/bplustree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class BPlusTree
private:
const size_t m_order;
Node* m_root;

size_t m_count;
};

#endif
Expand Down
18 changes: 8 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{}() } );
Expand All @@ -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" );
}
}

//
Expand Down

0 comments on commit dc2ea71

Please sign in to comment.