io.sirix.index.art.Node256 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirix-core Show documentation
Show all versions of sirix-core Show documentation
SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.
package io.sirix.index.art;
class Node256 extends InnerNode {
static final int NODE_SIZE = 256;
Node256(Node48 node) {
super(node, NODE_SIZE);
assert node.isFull();
byte[] keyIndex = node.getKeyIndex();
Node[] child = node.getChildren();
for (int i = 0; i < Node48.KEY_INDEX_SIZE; i++) {
byte index = keyIndex[i];
if (index == Node48.ABSENT) {
continue;
}
assert index >= 0 && index <= 47;
// index is byte, but gets type promoted
// https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.4-120
this.children[i] = child[index];
// update up link
replaceUplink(this, this.children[i]);
}
}
@Override
public Node findChild(byte partialKey) {
// We treat the 8 bits as unsigned int since we've got 256 slots
int index = Byte.toUnsignedInt(partialKey);
return children[index];
}
@Override
public void addChild(byte partialKey, Node child) {
// addChild would never be called on a full Node256
// since the corresponding findChild for any byte key
// would always find the byte since the Node is full.
assert !isFull();
int index = Byte.toUnsignedInt(partialKey);
assert this.children[index] == null;
createUplink(this, child, partialKey);
this.children[index] = child;
noOfChildren++;
}
@Override
public void replace(byte partialKey, Node newChild) {
int index = Byte.toUnsignedInt(partialKey);
assert children[index] != null;
children[index] = newChild;
createUplink(this, newChild, partialKey);
}
@Override
public void removeChild(byte partialKey) {
int index = Byte.toUnsignedInt(partialKey);
assert children[index] != null;
removeUplink(children[index]);
children[index] = null;
noOfChildren--;
}
@Override
public InnerNode grow() {
throw new UnsupportedOperationException("Span of ART is 8 bits, so Node256 is the largest node type.");
}
@Override
public boolean shouldShrink() {
return noOfChildren == Node48.NODE_SIZE;
}
@Override
public InnerNode shrink() {
assert shouldShrink();
return new Node48(this);
}
@Override
public Node first() {
assert noOfChildren > Node48.NODE_SIZE;
int i = 0;
while(children[i] == null)i++;
return children[i];
}
@Override
public Node last() {
assert noOfChildren > Node48.NODE_SIZE;
int i = NODE_SIZE - 1;
while(children[i] == null)i--;
return children[i];
}
@Override
public Node ceil(byte partialKey) {
for (int i = Byte.toUnsignedInt(partialKey); i < NODE_SIZE; i++) {
if (children[i] != null) {
return children[i];
}
}
return null;
}
@Override
public Node greater(byte partialKey) {
for (int i = Byte.toUnsignedInt(partialKey) + 1; i < NODE_SIZE; i++) {
if (children[i] != null) {
return children[i];
}
}
return null;
}
@Override
public Node lesser(byte partialKey) {
for (int i = Byte.toUnsignedInt(partialKey) - 1; i >= 0; i--) {
if (children[i] != null) {
return children[i];
}
}
return null;
}
@Override
public Node floor(byte partialKey) {
for (int i = Byte.toUnsignedInt(partialKey); i >= 0; i--) {
if (children[i] != null) {
return children[i];
}
}
return null;
}
@Override
public boolean isFull() {
return noOfChildren == NODE_SIZE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy