Search in sources :

Example 11 with ByteIterator

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;
}
Also used : ByteIterator(jetbrains.exodus.ByteIterator) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ByteIterator

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;
    }
}
Also used : ByteIterator(jetbrains.exodus.ByteIterator) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable)

Example 13 with ByteIterator

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);
    }
}
Also used : ByteIterator(jetbrains.exodus.ByteIterator)

Aggregations

ByteIterator (jetbrains.exodus.ByteIterator)13 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)3 ByteIterable (jetbrains.exodus.ByteIterable)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1