use of org.neo4j.kernel.impl.util.Bits in project neo4j by neo4j.
the class MetaDataStore method versionStringToLong.
/*
* The following two methods encode and decode a string that is presumably
* the store version into a long via Latin1 encoding. This leaves room for
* 7 characters and 1 byte for the length. Current string is
* 0.A.0 which is 5 chars, so we have room for expansion. When that
* becomes a problem we will be in a yacht, sipping alcoholic
* beverages of our choice. Or taking turns crashing golden
* helicopters. Anyway, it should suffice for some time and by then
* it should have become SEP.
*/
public static long versionStringToLong(String storeVersion) {
if (CommonAbstractStore.UNKNOWN_VERSION.equals(storeVersion)) {
return -1;
}
Bits bits = Bits.bits(8);
int length = storeVersion.length();
if (length == 0 || length > 7) {
throw new IllegalArgumentException(format("The given string %s is not of proper size for a store version string", storeVersion));
}
bits.put(length, 8);
for (int i = 0; i < length; i++) {
char c = storeVersion.charAt(i);
if (c >= 256) {
throw new IllegalArgumentException(format("Store version strings should be encode-able as Latin1 - %s is not", storeVersion));
}
// Just the lower byte
bits.put(c, 8);
}
return bits.getLong();
}
use of org.neo4j.kernel.impl.util.Bits in project neo4j by neo4j.
the class FullCheckIntegrationTest method inlinedLabelsLongRepresentation.
private long inlinedLabelsLongRepresentation(long... labelIds) {
long header = (long) labelIds.length << 36;
byte bitsPerLabel = (byte) (36 / labelIds.length);
Bits bits = bits(5);
for (long labelId : labelIds) {
bits.put(labelId, bitsPerLabel);
}
return header | bits.getLongs()[0];
}
use of org.neo4j.kernel.impl.util.Bits in project neo4j-mobile-android by neo4j-contrib.
the class DynamicArrayStore method getRightArray.
public Object getRightArray(byte[] bArray) {
byte typeId = bArray[0];
if (typeId == PropertyType.STRING.intValue()) {
ByteBuffer buf = ByteBuffer.wrap(bArray);
// Get rid of the type byte that we've already read
buf.get();
int arrayLength = buf.getInt();
String[] result = new String[arrayLength];
for (int i = 0; i < arrayLength; i++) {
int byteLength = buf.getInt();
byte[] stringByteArray = new byte[byteLength];
buf.get(stringByteArray);
result[i] = (String) PropertyStore.getStringFor(stringByteArray);
}
return result;
} else {
ShortArray type = ShortArray.typeOf(typeId);
Bits bits = Bits.bitsFromBytes(bArray);
// type, we already got it
bits.getByte();
int bitsUsedInLastByte = bits.getByte();
int requiredBits = bits.getByte();
if (requiredBits == 0)
return type.createArray(0);
int length = ((bArray.length - 3) * 8 - (8 - bitsUsedInLastByte)) / requiredBits;
Object result = type.createArray(length);
for (int i = 0; i < length; i++) {
type.get(result, i, bits, requiredBits);
}
return result;
}
}
use of org.neo4j.kernel.impl.util.Bits in project neo4j-mobile-android by neo4j-contrib.
the class DynamicArrayStore method allocateFromNumbers.
private Collection<DynamicRecord> allocateFromNumbers(long startBlock, Object array) {
ShortArray type = ShortArray.typeOf(array);
if (type == null) {
throw new IllegalArgumentException(array + " not a valid array type.");
}
int arrayLength = Array.getLength(array);
int requiredBits = type.calculateRequiredBitsForArray(array);
int totalBits = requiredBits * arrayLength;
int bytes = (totalBits - 1) / 8 + 1;
int bitsUsedInLastByte = totalBits % 8;
bitsUsedInLastByte = bitsUsedInLastByte == 0 ? 8 : bitsUsedInLastByte;
// type + rest + requiredBits header. TODO no need to use full bytes
bytes += 3;
Bits bits = Bits.bits(bytes);
bits.put((byte) type.intValue());
bits.put((byte) bitsUsedInLastByte);
bits.put((byte) requiredBits);
int length = arrayLength;
for (int i = 0; i < length; i++) {
type.put(Array.get(array, i), bits, requiredBits);
}
return allocateRecords(startBlock, bits.asBytes());
}
use of org.neo4j.kernel.impl.util.Bits in project neo4j by neo4j.
the class NodeLabelsFieldTest method inlinedLabelsLongRepresentation.
private long inlinedLabelsLongRepresentation(long... labelIds) {
long header = (long) labelIds.length << 36;
byte bitsPerLabel = (byte) (36 / labelIds.length);
Bits bits = bits(5);
for (long labelId : labelIds) {
bits.put(labelId, bitsPerLabel);
}
return header | bits.getLongs()[0];
}
Aggregations