Class NodeReference

java.lang.Object
com.apple.foundationdb.async.hnsw.NodeReference
Direct Known Subclasses:
NodeReferenceWithVector

public class NodeReference extends Object
Represents a reference to a node, uniquely identified by its primary key. It provides fundamental operations such as equality comparison, hashing, and string representation based on this key. It also serves as a base class for more specialized node references.
  • Constructor Details

    • NodeReference

      public NodeReference(@Nonnull Tuple primaryKey)
      Constructs a new NodeReference with the specified primary key.
      Parameters:
      primaryKey - the primary key of the node to reference; must not be null.
  • Method Details

    • getPrimaryKey

      @Nonnull public Tuple getPrimaryKey()
      Gets the primary key for this object.
      Returns:
      the primary key as a Tuple object, which is guaranteed to be non-null.
    • asNodeReferenceWithVector

      @Nonnull public NodeReferenceWithVector asNodeReferenceWithVector()
      Casts this object to a NodeReferenceWithVector.

      This method is intended to be used on subclasses that actually represent a node reference with a vector. For this base class or specific implementation, it is not a valid operation.

      Returns:
      this instance cast as a NodeReferenceWithVector
      Throws:
      IllegalStateException - always, to indicate that this object cannot be represented as a NodeReferenceWithVector.
    • equals

      public boolean equals(Object o)
      Compares this NodeReference to the specified object for equality.

      The result is true if and only if the argument is not null and is a NodeReference object that has the same primaryKey as this object.

      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare with this NodeReference for equality.
      Returns:
      true if the given object is equal to this one; false otherwise.
    • hashCode

      public int hashCode()
      Generates a hash code for this object based on the primary key.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object.
    • primaryKeys

      @Nonnull public static Iterable<Tuple> primaryKeys(@Nonnull Iterable<? extends NodeReference> neighbors)
      Helper to extract the primary keys from a given collection of node references.
      Parameters:
      neighbors - an iterable of NodeReference objects from which to extract primary keys.
      Returns:
      a lazily-evaluated Iterable of Tuples, representing the primary keys of the input nodes.