libcryfs/implementations/onblocks/datatreestore/DataTree.h

76 lines
2.7 KiB
C
Raw Normal View History

2015-01-23 04:39:36 +01:00
#pragma once
#ifndef BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREE_H_
#define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREE_H_
#include <memory>
#include <messmer/cpp-utils/macros.h>
#include <messmer/cpp-utils/optional_ownership_ptr.h>
#include "../datanodestore/DataNodeView.h"
2015-04-09 16:10:57 +02:00
//TODO Replace with C++14 once std::shared_mutex is supported
#include <boost/thread/shared_mutex.hpp>
2015-01-23 04:39:36 +01:00
namespace blockstore {
class Key;
}
2015-01-23 04:39:36 +01:00
namespace blobstore {
namespace onblocks {
namespace datanodestore {
class DataNodeStore;
class DataInnerNode;
class DataLeafNode;
class DataNode;
}
namespace datatreestore {
//TODO It is strange that DataLeafNode is still part in the public interface of DataTree. This should be separated somehow.
2015-01-23 04:39:36 +01:00
class DataTree {
public:
DataTree(datanodestore::DataNodeStore *nodeStore, std::unique_ptr<datanodestore::DataNode> rootNode);
virtual ~DataTree();
const blockstore::Key &key() const;
uint32_t maxBytesPerLeaf() const;
void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function<void (const datanodestore::DataLeafNode*, uint32_t)> func) const;
void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);
void resizeNumBytes(uint64_t newNumBytes);
uint64_t numStoredBytes() const;
2015-01-23 04:39:36 +01:00
private:
2015-04-09 16:10:57 +02:00
mutable boost::shared_mutex _mutex;
2015-01-23 04:39:36 +01:00
datanodestore::DataNodeStore *_nodeStore;
std::unique_ptr<datanodestore::DataNode> _rootNode;
2015-01-23 04:39:36 +01:00
std::unique_ptr<datanodestore::DataLeafNode> addDataLeaf();
void removeLastDataLeaf();
std::unique_ptr<datanodestore::DataNode> releaseRootNode();
friend class DataTreeStore;
2015-01-23 04:39:36 +01:00
std::unique_ptr<datanodestore::DataLeafNode> addDataLeafAt(datanodestore::DataInnerNode *insertPos);
2015-02-17 00:40:34 +01:00
cpputils::optional_ownership_ptr<datanodestore::DataNode> createChainOfInnerNodes(unsigned int num, datanodestore::DataLeafNode *leaf);
2015-01-23 04:39:36 +01:00
std::unique_ptr<datanodestore::DataLeafNode> addDataLeafToFullTree();
void deleteLastChildSubtree(datanodestore::DataInnerNode *node);
void ifRootHasOnlyOneChildReplaceRootWithItsChild();
2015-04-09 16:30:36 +02:00
//TODO Use underscore for private methods
void traverseLeaves(const datanodestore::DataNode *root, uint32_t leafOffset, uint32_t beginIndex, uint32_t endIndex, std::function<void (const datanodestore::DataLeafNode*, uint32_t)> func) const;
2015-02-25 23:08:16 +01:00
uint32_t leavesPerFullChild(const datanodestore::DataInnerNode &root) const;
2015-04-09 16:30:36 +02:00
uint64_t _numStoredBytes() const;
uint64_t _numStoredBytes(const datanodestore::DataNode &root) const;
cpputils::optional_ownership_ptr<datanodestore::DataLeafNode> LastLeaf(datanodestore::DataNode *root);
std::unique_ptr<datanodestore::DataLeafNode> LastLeaf(std::unique_ptr<datanodestore::DataNode> root);
void flush() const;
2015-01-23 04:39:36 +01:00
DISALLOW_COPY_AND_ASSIGN(DataTree);
};
}
}
}
#endif