io.sirix.index.art.BinaryComparableUtils 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;
/**
* Contains utilities to help with {@link BinaryComparable} key transformation.
*/
class BinaryComparableUtils {
private BinaryComparableUtils() {
// Effective Java Item 4
throw new AssertionError();
}
// 2^7 = 128
private static final int BYTE_SHIFT = 1 << Byte.SIZE - 1;
/**
* For signed types to be interpreted as unsigned
*/
static byte[] unsigned(byte[] key) {
key[0] = unsigned(key[0]);
return key;
}
/**
* For Node4, Node16 to interpret every byte as unsigned when storing partial keys.
* Node 48, Node256 simply use {@link Byte#toUnsignedInt(byte)}
* to index into their key arrays.
*/
static byte unsigned(byte b) {
return (byte) (b ^ BYTE_SHIFT);
}
// passed b must have been interpreted as unsigned already
// this is the reverse of unsigned
static byte signed(byte b) {
return unsigned(b);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy