Package smile.neighbor
Record Class Neighbor<K,V>
java.lang.Object
java.lang.Record
smile.neighbor.Neighbor<K,V>
- Type Parameters:
K
- the type of keys.V
- the type of associated objects.- Record Components:
key
- the key of neighbor.value
- the value of neighbor.index
- the index of neighbor object in the dataset.distance
- the distance between the query and the neighbor.
- All Implemented Interfaces:
Comparable<Neighbor<K,
V>>
public record Neighbor<K,V> (K key, V value, int index, double distance)
extends Record
implements Comparable<Neighbor<K,V>>
The immutable object encapsulates the results of nearest neighbor search.
A returned neighbor for nearest neighbor search contains the key of object
(e.g. the weight vector of a neuron) and the object itself (e.g. a neuron,
which also contains other information beyond weight vector), an index of
object in the dataset, which is often useful, and the distance between
the query key to the object key.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
double
distance()
Returns the value of thedistance
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.int
index()
Returns the value of theindex
record component.key()
Returns the value of thekey
record component.static <T> Neighbor
<T, T> of
(T key, int index, double distance) Creates a neighbor object, of which key and object are the same.toString()
Returns a string representation of this record class.value()
Returns the value of thevalue
record component.
-
Constructor Details
-
Method Details
-
compareTo
- Specified by:
compareTo
in interfaceComparable<K>
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
of
Creates a neighbor object, of which key and object are the same.- Type Parameters:
T
- the data type of key and object.- Parameters:
key
- the query key.index
- the index of object.distance
- the distance between query key and neighbor.- Returns:
- the neighbor object.
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
key
Returns the value of thekey
record component.- Returns:
- the value of the
key
record component
-
value
Returns the value of thevalue
record component.- Returns:
- the value of the
value
record component
-
index
public int index()Returns the value of theindex
record component.- Returns:
- the value of the
index
record component
-
distance
public double distance()Returns the value of thedistance
record component.- Returns:
- the value of the
distance
record component
-