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

    Constructors
    Constructor
    Description
    Neighbor(K key, V value, int index, double distance)
    Creates an instance of a Neighbor record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    double
    Returns the value of the distance record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the index record component.
    key()
    Returns the value of the key 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.
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Neighbor

      public Neighbor(K key, V value, int index, double distance)
      Creates an instance of a Neighbor record class.
      Parameters:
      key - the value for the key record component
      value - the value for the value record component
      index - the value for the index record component
      distance - the value for the distance record component
  • Method Details

    • compareTo

      public int compareTo(Neighbor<K,V> o)
      Specified by:
      compareTo in interface Comparable<K>
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • of

      public static <T> Neighbor<T,T> of(T key, int index, double distance)
      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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      public K key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • value

      public V value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • index

      public int index()
      Returns the value of the index record component.
      Returns:
      the value of the index record component
    • distance

      public double distance()
      Returns the value of the distance record component.
      Returns:
      the value of the distance record component