use of jetbrains.exodus.ByteIterator in project xodus by JetBrains.
the class PatriciaTreeBase method getNode.
@Nullable
protected NodeBase getNode(@NotNull final ByteIterable key) {
final ByteIterator it = key.iterator();
NodeBase node = getRoot();
do {
if (NodeBase.MatchResult.getMatchingLength(node.matchesKeySequence(it)) < 0) {
return null;
}
if (!it.hasNext()) {
break;
}
node = node.getChild(this, it.next());
} while (node != null);
return node;
}
use of jetbrains.exodus.ByteIterator in project xodus by JetBrains.
the class PatriciaTreeMutable method putRight.
@Override
public void putRight(@NotNull final ByteIterable key, @NotNull final ByteIterable value) {
final ByteIterator it = key.iterator();
MutableNode node = root;
MutableNode prev = null;
byte prevFirstByte = (byte) 0;
while (true) {
final long matchResult = node.matchesKeySequence(it);
final int matchingLength = NodeBase.MatchResult.getMatchingLength(matchResult);
if (matchingLength < 0) {
if (!NodeBase.MatchResult.hasNext(matchResult)) {
throw new IllegalArgumentException();
}
final MutableNode prefix = node.splitKey(-matchingLength - 1, NodeBase.MatchResult.getKeyByte(matchResult));
prefix.hangRight(NodeBase.MatchResult.getNextByte(matchResult), it).setValue(value);
if (prev == null) {
root = new MutableRoot(prefix, root.sourceAddress);
} else {
prev.setChild(prevFirstByte, prefix);
}
++size;
break;
}
if (!it.hasNext()) {
if (node.hasChildren() || node.hasValue()) {
throw new IllegalArgumentException();
}
node.setValue(value);
++size;
break;
}
final byte nextByte = it.next();
final NodeBase child = node.getRightChild(this, nextByte);
if (child == null) {
if (node.hasChildren() || node.hasKey() || node.hasValue()) {
node.hangRight(nextByte, it).setValue(value);
} else {
node.setKeySequence(new ArrayByteIterable(nextByte, it));
node.setValue(value);
}
++size;
break;
}
prev = node;
prevFirstByte = nextByte;
final MutableNode mutableChild = child.getMutableCopy(this);
if (!child.isMutable()) {
node.setRightChild(nextByte, mutableChild);
}
node = mutableChild;
}
}
use of jetbrains.exodus.ByteIterator in project xodus by JetBrains.
the class TreeMetaInfo method load.
public static TreeMetaInfo load(@NotNull final EnvironmentImpl environment, @NotNull final ByteIterable iterable) {
final ByteIterator it = iterable.iterator();
final byte flagsByte = it.next();
if ((flagsByte & KEY_PREFIXING_BIT) == 0) {
return BTreeMetaInfo.load(environment, flagsByte, it);
} else {
return PatriciaMetaInfo.load(environment, flagsByte, it);
}
}
Aggregations