Class Varint
java.lang.Object
org.eclipse.rdf4j.sail.lmdb.Varint
Encodes and decodes unsigned values using variable-length encoding.
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated, for removal: This API element is subject to removal in a future version. - 
Method Summary
Modifier and TypeMethodDescriptionstatic intcalcLengthUnsigned(long value) Calculates required length in bytes to encode the given long value using variable-length encoding.static intcalcListLengthUnsigned(long a, long b, long c, long d) Calculates required length in bytes to encode a list of four long values using variable-length encoding.static intfirstToLength(byte a0) Determines length of an encoded varint value by inspecting the first byte.static longreadListElementUnsigned(ByteBuffer bb, int index) Decodes a single element of a list of variable-length long values from a buffer.static voidreadListUnsigned(ByteBuffer bb, int[] indexMap, long[] values) Decodes multiple values using variable-length encoding from the given buffer.static voidreadListUnsigned(ByteBuffer bb, long[] values) Decodes multiple values using variable-length encoding from the given buffer.static voidreadQuadUnsigned(ByteBuffer bb, int[] indexMap, long[] values) static voidreadQuadUnsigned(ByteBuffer bb, long[] values) static longDecodes a value using SQLite's variable-length integer encoding.static longreadUnsigned(ByteBuffer bb, int pos) Decodes a value using the variable-length encoding of SQLite.static longstatic voidstatic voidwriteListUnsigned(ByteBuffer bb, long[] values) Encodes multiple values using variable-length encoding into the given buffer.static voidwriteUnsigned(ByteBuffer bb, long value) Encodes a value using the variable-length encoding of SQLite. 
- 
Method Details
- 
writeUnsigned
Encodes a value using the variable-length encoding of SQLite.The encoding has the following properties:
- Smaller (and more common) values use fewer bytes and take up less space than larger (and less common) values.
 - The length of any varint can be determined by looking at just the first byte of the encoding.
 - Lexicographical and numeric ordering for varints are the same. Hence if a group of varints are ordered
lexicographically (that is to say, if they are ordered by 
Arrays.compare(byte[], byte[])with shorter varints coming first) then those varints will also be in numeric order. This property means that varints can be used as keys in the key/value backend storage and the records will occur in numerical order of the keys. 
A0 Value 0–240 A0 241–248 240 + 256 × (A0 – 241) + A1 249 2288 + 256 × A1 + A2 250 A1…A3 as a 3-byte big-endian integer 251 A1…A4 as a 4-byte big-endian integer 252 A1…A5 as a 5-byte big-endian integer 253 A1…A6 as a 6-byte big-endian integer 254 A1…A7 as a 7-byte big-endian integer 255 A1…A8 as a 8-byte big-endian integer - Parameters:
 bb- buffer for writing bytesvalue- value to encode
 - 
calcLengthUnsigned
public static int calcLengthUnsigned(long value) Calculates required length in bytes to encode the given long value using variable-length encoding.- Parameters:
 value- the value value- Returns:
 - length in bytes
 
 - 
calcListLengthUnsigned
public static int calcListLengthUnsigned(long a, long b, long c, long d) Calculates required length in bytes to encode a list of four long values using variable-length encoding.- Parameters:
 a- first valueb- second valuec- third valued- fourth value- Returns:
 - length in bytes
 
 - 
readUnsigned
Decodes a value using SQLite's variable-length integer encoding. Lead-byte layout → number of additional bytes: 0..240 → 0 241..248→ 1 249 → 2 250..255→ 3..8 (i.e., 250→3, 251→4, …, 255→8)- Parameters:
 bb- buffer for reading bytes- Returns:
 - decoded value
 - Throws:
 IllegalArgumentException- if encoded varint is longer than 9 bytes- See Also:
 
 - 
skipUnsigned
- Throws:
 IllegalArgumentException
 - 
readUnsignedHeap
- Throws:
 IllegalArgumentException
 - 
readUnsigned
Decodes a value using the variable-length encoding of SQLite.- Parameters:
 bb- buffer for reading bytes- Returns:
 - decoded value
 - Throws:
 IllegalArgumentException- if encoded varint is longer than 9 bytes- See Also:
 
 - 
firstToLength
public static int firstToLength(byte a0) Determines length of an encoded varint value by inspecting the first byte.- Parameters:
 a0- first byte of varint value- Returns:
 - decoded value
 
 - 
readListElementUnsigned
Decodes a single element of a list of variable-length long values from a buffer.- Parameters:
 bb- buffer for reading bytesindex- the element's index- Returns:
 - the decoded value
 
 - 
writeListUnsigned
Encodes multiple values using variable-length encoding into the given buffer.- Parameters:
 bb- buffer for writing bytesvalues- array with values to write
 - 
readListUnsigned
Decodes multiple values using variable-length encoding from the given buffer.- Parameters:
 bb- buffer for writing bytesvalues- array for the result values
 - 
readQuadUnsigned
 - 
readListUnsigned
Decodes multiple values using variable-length encoding from the given buffer.- Parameters:
 bb- buffer for writing bytesindexMap- map for indexes of values within values arrayvalues- array for the result values
 - 
readQuadUnsigned
 
 -