Skip to content

@saehrimnir/druidjs / spatial_tree

Function: spatial_tree()

ts
function spatial_tree<T>(elements: T[], parameters: {
  metric: Metric;
  seed: number;
}): 
  | KDTree<T>
| BallTree<T>;

Defined in: knn/spatial_tree.js:30

Picks the fastest spatial index that is still correct for the given metric.

Returns a KDTree for metrics it can prune soundly, and a BallTree — which only relies on the triangle inequality and therefore works for any metric — otherwise.

Type Parameters

Type ParameterDescription
T extends number[] | Float64Array<ArrayBufferLike>

Parameters

ParameterTypeDescription
elementsT[]Elements to index.
parameters{ metric: Metric; seed: number; }Metric and seed for the tree.
parameters.metricMetric-
parameters.seednumber-

Returns

| KDTree<T> | BallTree<T>

The constructed index.