2015-01-22 23:37:03 +01:00
|
|
|
#include "DataInnerNode.h"
|
|
|
|
#include "DataNodeStore.h"
|
2014-12-09 18:53:11 +01:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
2015-02-20 19:46:52 +01:00
|
|
|
using std::make_unique;
|
2014-12-09 18:53:11 +01:00
|
|
|
using blockstore::Block;
|
2015-04-25 02:55:34 +02:00
|
|
|
using cpputils::Data;
|
2014-12-13 19:17:08 +01:00
|
|
|
using blockstore::Key;
|
2014-12-09 18:53:11 +01:00
|
|
|
|
|
|
|
namespace blobstore {
|
|
|
|
namespace onblocks {
|
2014-12-13 19:17:08 +01:00
|
|
|
namespace datanodestore {
|
2014-12-09 18:53:11 +01:00
|
|
|
|
2015-01-24 22:27:14 +01:00
|
|
|
DataInnerNode::DataInnerNode(DataNodeView view)
|
|
|
|
: DataNode(std::move(view)) {
|
2015-02-20 19:46:52 +01:00
|
|
|
assert(depth() > 0);
|
2014-12-09 18:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataInnerNode::~DataInnerNode() {
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:46:52 +01:00
|
|
|
unique_ptr<DataInnerNode> DataInnerNode::InitializeNewNode(unique_ptr<Block> block, const DataNode &first_child) {
|
|
|
|
DataNodeView node(std::move(block));
|
2015-03-04 20:58:39 +01:00
|
|
|
node.setDepth(first_child.depth() + 1);
|
|
|
|
node.setSize(1);
|
2015-02-20 19:46:52 +01:00
|
|
|
auto result = make_unique<DataInnerNode>(std::move(node));
|
|
|
|
result->ChildrenBegin()->setKey(first_child.key());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-12-13 17:43:02 +01:00
|
|
|
uint32_t DataInnerNode::numChildren() const {
|
2015-03-04 20:58:39 +01:00
|
|
|
return node().Size();
|
2014-12-13 12:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataInnerNode::ChildEntry *DataInnerNode::ChildrenBegin() {
|
|
|
|
return const_cast<ChildEntry*>(const_cast<const DataInnerNode*>(this)->ChildrenBegin());
|
2014-12-10 16:48:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-11 00:24:50 +01:00
|
|
|
const DataInnerNode::ChildEntry *DataInnerNode::ChildrenBegin() const {
|
2014-12-13 17:43:02 +01:00
|
|
|
return node().DataBegin<ChildEntry>();
|
2014-12-10 16:48:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 23:37:03 +01:00
|
|
|
DataInnerNode::ChildEntry *DataInnerNode::ChildrenEnd() {
|
|
|
|
return const_cast<ChildEntry*>(const_cast<const DataInnerNode*>(this)->ChildrenEnd());
|
|
|
|
}
|
|
|
|
|
2014-12-11 00:24:50 +01:00
|
|
|
const DataInnerNode::ChildEntry *DataInnerNode::ChildrenEnd() const {
|
2015-03-04 20:58:39 +01:00
|
|
|
return ChildrenBegin() + node().Size();
|
2014-12-10 16:48:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:41:55 +01:00
|
|
|
DataInnerNode::ChildEntry *DataInnerNode::LastChild() {
|
|
|
|
return const_cast<ChildEntry*>(const_cast<const DataInnerNode*>(this)->LastChild());
|
|
|
|
}
|
|
|
|
|
|
|
|
const DataInnerNode::ChildEntry *DataInnerNode::LastChild() const {
|
2015-03-04 20:58:39 +01:00
|
|
|
return getChild(numChildren()-1);
|
2014-12-10 16:48:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:41:55 +01:00
|
|
|
DataInnerNode::ChildEntry *DataInnerNode::getChild(unsigned int index) {
|
|
|
|
return const_cast<ChildEntry*>(const_cast<const DataInnerNode*>(this)->getChild(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
const DataInnerNode::ChildEntry *DataInnerNode::getChild(unsigned int index) const {
|
|
|
|
assert(index < numChildren());
|
|
|
|
return ChildrenBegin()+index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataInnerNode::addChild(const DataNode &child) {
|
2015-02-25 22:30:48 +01:00
|
|
|
assert(numChildren() < maxStoreableChildren());
|
2015-01-23 02:41:55 +01:00
|
|
|
assert(child.depth() == depth()-1);
|
2015-03-04 20:58:39 +01:00
|
|
|
node().setSize(node().Size()+1);
|
2015-01-23 02:41:55 +01:00
|
|
|
LastChild()->setKey(child.key());
|
|
|
|
}
|
|
|
|
|
2015-02-22 19:30:42 +01:00
|
|
|
void DataInnerNode::removeLastChild() {
|
2015-03-04 20:58:39 +01:00
|
|
|
assert(node().Size() > 1);
|
|
|
|
node().setSize(node().Size()-1);
|
2015-02-22 19:30:42 +01:00
|
|
|
}
|
|
|
|
|
2015-02-25 22:30:48 +01:00
|
|
|
uint32_t DataInnerNode::maxStoreableChildren() const {
|
|
|
|
return node().layout().maxChildrenPerInnerNode();
|
|
|
|
}
|
|
|
|
|
2014-12-09 18:53:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-12-13 19:17:08 +01:00
|
|
|
}
|