Record Class BinaryVector
java.lang.Object
java.lang.Record
io.micronaut.data.model.vector.BinaryVector
- Record Components:
data- the packed bits, eight dimensions per byte, most significant bit first (a defensive copy is returned by accessors)
- All Implemented Interfaces:
Vector
@TypeDef(type=OBJECT,
converter=BinaryVectorAttributeConverter.class)
public record BinaryVector(byte[] data)
extends Record
implements Vector
Bit-packed immutable vector, mapped to Oracle
VECTOR(n, BINARY) columns.
Each dimension is one bit. The backing array packs eight dimensions per byte, most significant bit
first, so a vector of n dimensions holds n / 8 bytes and the number of dimensions is
always a multiple of 8. This is the layout Oracle uses for BINARY vectors.
Compare binary vectors with ScoringFunction.HAMMING
or ScoringFunction.JACCARD.
The array conversions of Vector return one element per dimension, 0 or 1.
Use data() for the packed bytes.
- Since:
- 5.3.0
- Author:
- Graeme Rocher
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]data()Returns the value of thedatarecord component.intbooleanIndicates whether some other object is "equal to" this one.booleanget(int index) Returns the bit at the given dimension.getType()Returnsbyte: the type of the packed backing array.inthashCode()Returns a hash code value for this object.static @NonNull BinaryVectorof(boolean... bits) Creates a binary vector with one dimension per bit.boolean[]byte[]Convert this vector to a new byte array copy.double[]Convert this vector to a new double array copy.float[]Convert this vector to a new float array copy.@NonNull StringtoString()Returns a string representation of this record class.Methods inherited from interface Vector
toSparseByteVector, toSparseDoubleVector, toSparseFloatVector
-
Constructor Details
-
BinaryVector
public BinaryVector(byte[] data) Creates a binary vector from packed bits.- Parameters:
data- the packed bits, eight dimensions per byte, most significant bit first
-
-
Method Details
-
of
Creates a binary vector with one dimension per bit.- Parameters:
bits- the bits; the length must be a multiple of 8- Returns:
- the binary vector
-
data
-
dimensions
public int dimensions()- Returns:
- the number of dimensions, which is the number of bits
-
get
public boolean get(int index) Returns the bit at the given dimension.- Parameters:
index- the dimension, from0- Returns:
truewhen the bit is set
-
toBooleanArray
public boolean[] toBooleanArray()- Returns:
- one element per dimension,
truewhere the bit is set
-
getType
-
toFloatArray
public float[] toFloatArray()Description copied from interface:VectorConvert this vector to a new float array copy.- Specified by:
toFloatArrayin interfaceVector- Returns:
- a new float[] with the vector content
-
toDoubleArray
public double[] toDoubleArray()Description copied from interface:VectorConvert this vector to a new double array copy.- Specified by:
toDoubleArrayin interfaceVector- Returns:
- a new double[] with the vector content
-
toByteArray
public byte[] toByteArray()Description copied from interface:VectorConvert this vector to a new byte array copy.- Specified by:
toByteArrayin interfaceVector- Returns:
- a new byte[] with the vector content
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object).
-