Package io.github.jbellis.jvector.util
Class BytesRef
java.lang.Object
io.github.jbellis.jvector.util.BytesRef
- All Implemented Interfaces:
Cloneable,Comparable<BytesRef>
Represents byte[], as a slice (offset + length) into an existing byte[]. The
bytes
member should never be null; use EMPTY_BYTES if necessary.
BytesRef implements Comparable. The underlying byte arrays are sorted
lexicographically, numerically treating elements as unsigned. This is identical to Unicode
codepoint order.
-
Field Summary
FieldsModifier and TypeFieldDescriptionbyte[]The contents of the BytesRef.static final byte[]An empty byte array for convenienceintLength of used bytes.intOffset of first valid byte. -
Constructor Summary
ConstructorsConstructorDescriptionBytesRef(byte[] bytes) This instance will directly reference bytes w/o making a copy.BytesRef(byte[] bytes, int offset, int length) This instance will directly reference bytes w/o making a copy.BytesRef(int capacity) Create a BytesRef pointing to a new array of sizecapacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbytesEquals(BytesRef other) Expert: compares the bytes against another BytesRef, returning true if the bytes are equal.clone()Returns a shallow clone of this instance (the underlying bytes are not copied and will be shared by both the returned object and this object.intUnsigned byte order comparisonbooleanbooleanisValid()Performs internal consistency checks.toString()Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65]
-
Field Details
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTESAn empty byte array for convenience -
bytes
public byte[] bytesThe contents of the BytesRef. Should never benull. -
offset
public int offsetOffset of first valid byte. -
length
public int lengthLength of used bytes.
-
-
Constructor Details
-
BytesRef
public BytesRef(byte[] bytes, int offset, int length) This instance will directly reference bytes w/o making a copy. bytes should not be null. -
BytesRef
public BytesRef(byte[] bytes) This instance will directly reference bytes w/o making a copy. bytes should not be null -
BytesRef
public BytesRef(int capacity) Create a BytesRef pointing to a new array of sizecapacity. Offset and length will both be zero.
-
-
Method Details
-
bytesEquals
Expert: compares the bytes against another BytesRef, returning true if the bytes are equal.- Parameters:
other- Another BytesRef, should not be null.
-
clone
Returns a shallow clone of this instance (the underlying bytes are not copied and will be shared by both the returned object and this object. -
equals
-
toString
Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65] -
compareTo
Unsigned byte order comparison- Specified by:
compareToin interfaceComparable<BytesRef>
-
isValid
public boolean isValid()Performs internal consistency checks. Always returns true (or throws IllegalStateException)
-