nearestNeighbour method

List<Object>? nearestNeighbour(
  1. ItemDistance itemDist
)

Finds the two nearest items in the tree, using {@link ItemDistance} as the distance metric. A Branch-and-Bound tree traversal algorithm is used to provide an efficient search.

If the tree is empty, the return value is null If it is required to find only pairs of distinct items, the {@link ItemDistance} function must be anti-reflexive.

@param itemDist a distance metric applicable to the items in this tree @return the pair of the nearest items or null if the tree is empty

Implementation

List<Object>? nearestNeighbour(ItemDistance itemDist) {
  if (isEmpty()) return null;

  // if tree has only one item this will return null
  BoundablePair bp =
      new BoundablePair(this.getRoot(), this.getRoot(), itemDist);
  return nearestNeighbourWithPair(bp);
}