Skip to content

Commit

Permalink
Merge pull request #11 from romz-pl/feature-get-function
Browse files Browse the repository at this point in the history
Feature get function
  • Loading branch information
romz-pl authored Oct 28, 2017
2 parents 902da55 + 927bac8 commit a53a1e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
15 changes: 12 additions & 3 deletions src/bplustree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ bool BPlusTree::isEmpty() const
//
//
//
Value BPlusTree::get( Key key ) const
Value BPlusTree::get( Key key )
{
assert( 0 );
return Value();
LeafNode* leafNode = findLeafNode( key );
if( !leafNode )
{
throw std::runtime_error( "Key not found (LeafNode)" );
}
Record * rec = leafNode->lookup( key );
if( !rec )
{
throw std::runtime_error( "Key not found (Record)" );
}
return rec->value();
}

//
Expand Down
2 changes: 1 addition & 1 deletion src/bplustree.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BPlusTree


bool isEmpty() const;
Value get( Key key ) const;
Value get( Key key );
void insert( Key key, Value value );
void remove( Key key );
void destroyTree();
Expand Down
7 changes: 4 additions & 3 deletions src/key.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "key.h"
#include <limits>
// #include <limits>


//
Expand Down Expand Up @@ -73,6 +73,7 @@ std::string Key::ToString() const
//
Key Key::Dummy()
{
const int64_t v = std::numeric_limits< int64_t >::max();
return Key( v );
//const int64_t v = std::numeric_limits< int64_t >::max();
// return Key( v );
return Key( -1 );
}
21 changes: 11 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ void Check()
for( Key k : key )
{
const Value value = Value( GetRandomString() );
// std::cout << k.ToString() << " " << value.ToString() << std::endl << std::flush;

bPlusTree.insert( k, value );
stlMap.insert( std::make_pair( k, value ) );
}

return;

// Make key randomly distributed other then inserted
std::shuffle( key.begin(), key.end(), std::mt19937{ std::random_device{}() } );

Expand All @@ -71,10 +71,11 @@ 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,10 +87,10 @@ void Check()
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 a53a1e4

Please sign in to comment.