*
* It extends HTNode by adding support for child nodes, and also extensions.
*
- * @author alexmont
+ * @author Alexandre Montplaisir
*
*/
class CoreNode extends HTNode {
/**
* Initial constructor. Use this to initialize a new EMPTY node.
*
- * @param tree
- * The HistoryTree to which this node belongs
+ * @param config
+ * Configuration of the History Tree
* @param seqNumber
* The (unique) sequence number assigned to this particular node
* @param parentSeqNumber
* @param start
* The earliest timestamp stored in this node
*/
- CoreNode(HistoryTree tree, int seqNumber, int parentSeqNumber,
+ CoreNode(HTConfig config, int seqNumber, int parentSeqNumber,
long start) {
- super(tree, seqNumber, parentSeqNumber, start);
+ super(config, seqNumber, parentSeqNumber, start);
this.nbChildren = 0;
- int size = getTree().getConfig().getMaxChildren();
+ int size = config.getMaxChildren();
/*
* We instantiate the two following arrays at full size right away,
@Override
protected void readSpecificHeader(ByteBuffer buffer) {
- int size = getTree().getConfig().getMaxChildren();
+ int size = getConfig().getMaxChildren();
extension = buffer.getInt();
nbChildren = buffer.getInt();
@Override
protected void writeSpecificHeader(ByteBuffer buffer) {
- int size = getTree().getConfig().getMaxChildren();
+ int size = getConfig().getMaxChildren();
buffer.putInt(extension);
buffer.putInt(nbChildren);
* The SHTNode object of the new child
*/
void linkNewChild(CoreNode childNode) {
- assert (this.nbChildren < getTree().getConfig().getMaxChildren());
+ assert (this.nbChildren < getConfig().getMaxChildren());
this.children[nbChildren] = childNode.getSequenceNumber();
this.childStart[nbChildren] = childNode.getNodeStart();
@Override
protected int getTotalHeaderSize() {
- int maxChildren = getTree().getConfig().getMaxChildren();
+ int maxChildren = getConfig().getMaxChildren();
int specificSize =
SIZE_INT /* 1x int (extension node) */
+ SIZE_INT /* 1x int (nbChildren) */
/**
* The base class for all the types of nodes that go in the History Tree.
*
- * @author alexmont
+ * @author Alexandre Montplaisir
*/
abstract class HTNode {
*/
protected static final int DATA_ENTRY_SIZE = 25;
- /* Reference to the History Tree to whom this node belongs */
- private final HistoryTree ownerTree;
+ /* Configuration of the History Tree to which belongs this node */
+ private final HTConfig config;
/* Time range of this node */
private final long nodeStart;
/* Vector containing all the intervals contained in this node */
private final List<HTInterval> intervals;
- HTNode(HistoryTree tree, int seqNumber, int parentSeqNumber, long start) {
- this.ownerTree = tree;
+ HTNode(HTConfig config, int seqNumber, int parentSeqNumber, long start) {
+ this.config = config;
this.nodeStart = start;
this.sequenceNumber = seqNumber;
this.parentSequenceNumber = parentSeqNumber;
- this.stringSectionOffset = ownerTree.getConfig().getBlockSize();
+ this.stringSectionOffset = config.getBlockSize();
this.isDone = false;
this.intervals = new ArrayList<HTInterval>();
}
* Reader factory constructor. Build a Node object (of the right type) by
* reading a block in the file.
*
- * @param tree
- * Reference to the HT which will own this node
+ * @param config
+ * Configuration of the History Tree
* @param fc
* FileChannel to the history file, ALREADY SEEKED at the start
* of the node.
* @throws IOException
*/
- static final HTNode readNode(HistoryTree tree, FileChannel fc)
+ static final HTNode readNode(HTConfig config, FileChannel fc)
throws IOException {
HTNode newNode = null;
int res, i;
- ByteBuffer buffer = ByteBuffer.allocate(tree.getConfig().getBlockSize());
+ ByteBuffer buffer = ByteBuffer.allocate(config.getBlockSize());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
res = fc.read(buffer);
- assert (res == tree.getConfig().getBlockSize());
+ assert (res == config.getBlockSize());
buffer.flip();
/* Read the common header part */
switch (type) {
case 1:
/* Core nodes */
- newNode = new CoreNode(tree, seqNb, parentSeqNb, start);
+ newNode = new CoreNode(config, seqNb, parentSeqNb, start);
newNode.readSpecificHeader(buffer);
break;
}
final void writeSelf(FileChannel fc) throws IOException {
- final int blockSize = ownerTree.getConfig().getBlockSize();
+ final int blockSize = config.getBlockSize();
int curStringsEntryEndPos = blockSize;
ByteBuffer buffer = ByteBuffer.allocate(blockSize);
// Accessors
// ------------------------------------------------------------------------
- protected HistoryTree getTree() {
- return ownerTree;
+ HTConfig getConfig() {
+ return config;
}
long getNodeStart() {
* (used space / total usable space, which excludes the header)
*/
long getNodeUsagePRC() {
- final int blockSize = ownerTree.getConfig().getBlockSize();
+ final int blockSize = config.getBlockSize();
float freePercent = (float) this.getNodeFreeSpace()
/ (float) (blockSize - this.getTotalHeaderSize())
* 100F;