fix a bug in btree lookup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "transaction_manager.h"
|
||||
#include "core_map.h"
|
||||
#include "space_map_core.h"
|
||||
#include "btree.h"
|
||||
|
||||
#define BOOST_TEST_MODULE BTreeTests
|
||||
@@ -16,7 +16,7 @@ namespace {
|
||||
|
||||
transaction_manager::ptr
|
||||
create_tm() {
|
||||
block_manager<>::ptr bm(new block_manager<>("./test.data", NR_BLOCKS));
|
||||
block_manager<>::ptr bm(new block_manager<>("./test.data", NR_BLOCKS, 4, true));
|
||||
space_map::ptr sm(new core_map(NR_BLOCKS));
|
||||
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
||||
return tm;
|
||||
@@ -36,17 +36,26 @@ namespace {
|
||||
//
|
||||
class constraint_visitor : public btree<1, uint64_traits>::visitor {
|
||||
public:
|
||||
bool visit_internal(unsigned level, bool is_root, btree_detail::node_ref<uint64_traits> const &n) {
|
||||
typedef btree_detail::node_ref<uint64_traits> internal_node;
|
||||
typedef btree_detail::node_ref<uint64_traits> leaf_node;
|
||||
|
||||
bool visit_internal(unsigned level, bool sub_root,
|
||||
boost::optional<uint64_t> key,
|
||||
internal_node const &n) {
|
||||
check_duplicate_block(n.get_location());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit_internal_leaf(unsigned level, bool is_root, btree_detail::node_ref<uint64_traits> const &n) {
|
||||
bool visit_internal_leaf(unsigned level, bool sub_root,
|
||||
boost::optional<uint64_t> key,
|
||||
internal_node const &n) {
|
||||
check_duplicate_block(n.get_location());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit_leaf(unsigned level, bool is_root, btree_detail::node_ref<uint64_traits> const &n) {
|
||||
bool visit_leaf(unsigned level, bool sub_root,
|
||||
boost::optional<uint64_t> key,
|
||||
leaf_node const &n) {
|
||||
check_duplicate_block(n.get_location());
|
||||
return true;
|
||||
}
|
||||
@@ -77,7 +86,7 @@ namespace {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_btree_contains_nothing)
|
||||
{
|
||||
auto tree = create_btree();
|
||||
btree<1, uint64_traits>::ptr tree = create_btree();
|
||||
check_constraints(tree);
|
||||
|
||||
for (uint64_t i = 0; i < 1000; i++) {
|
||||
@@ -90,19 +99,46 @@ BOOST_AUTO_TEST_CASE(insert_works)
|
||||
{
|
||||
unsigned const COUNT = 100000;
|
||||
|
||||
auto tree = create_btree();
|
||||
btree<1, uint64_traits>::ptr tree = create_btree();
|
||||
for (uint64_t i = 0; i < COUNT; i++) {
|
||||
uint64_t key[1] = {i * 7};
|
||||
uint64_t value = i;
|
||||
|
||||
tree->insert(key, value);
|
||||
|
||||
auto l = tree->lookup(key);
|
||||
BOOST_CHECK(l);
|
||||
btree<1, uint64_traits>::maybe_value l = tree->lookup(key);
|
||||
BOOST_REQUIRE(l);
|
||||
BOOST_CHECK_EQUAL(*l, i);
|
||||
}
|
||||
|
||||
check_constraints(tree);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(insert_does_not_insert_imaginary_values)
|
||||
{
|
||||
btree<1, uint64_traits>::ptr tree = create_btree();
|
||||
uint64_t key[1] = {0};
|
||||
uint64_t value = 100;
|
||||
|
||||
btree<1, uint64_traits>::maybe_value l = tree->lookup(key);
|
||||
BOOST_CHECK(!l);
|
||||
|
||||
key[0] = 1;
|
||||
l = tree->lookup(key);
|
||||
BOOST_CHECK(!l);
|
||||
|
||||
key[0] = 0;
|
||||
tree->insert(key, value);
|
||||
|
||||
l = tree->lookup(key);
|
||||
BOOST_REQUIRE(l);
|
||||
BOOST_CHECK_EQUAL(*l, 100);
|
||||
|
||||
key[0] = 1;
|
||||
l = tree->lookup(key);
|
||||
BOOST_CHECK(!l);
|
||||
|
||||
check_constraints(tree);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user