Skip to main content

SpatialBackend

Trait SpatialBackend 

Source
pub trait SpatialBackend<T, C, const D: usize>: Send + Sync
where C: CoordType,
{ // Required methods fn insert(&mut self, point: Point<C, D>, payload: T) -> EntryId; fn remove(&mut self, id: EntryId) -> Option<T>; fn range_query(&self, bbox: &BBox<C, D>) -> Vec<(EntryId, &T)>; fn knn_query( &self, point: &Point<C, D>, k: usize, ) -> Vec<(f64, EntryId, &T)>; fn spatial_join( &self, other: &dyn SpatialBackend<T, C, D>, ) -> Vec<(EntryId, EntryId)>; fn bulk_load(entries: Vec<(Point<C, D>, T)>) -> Self where Self: Sized; fn len(&self) -> usize; fn kind(&self) -> BackendKind; fn all_entries(&self) -> Vec<(Point<C, D>, EntryId, &T)>; // Provided method fn is_empty(&self) -> bool { ... } }
Expand description

Uniform interface implemented by all spatial index backends.

§Type Parameters

  • T: payload type stored alongside each point
  • C: coordinate scalar type (must implement CoordType)
  • D: number of spatial dimensions (const generic)

Required Methods§

Source

fn insert(&mut self, point: Point<C, D>, payload: T) -> EntryId

Insert a point with an associated payload. Returns the unique EntryId assigned to this entry.

Source

fn remove(&mut self, id: EntryId) -> Option<T>

Remove the entry with the given EntryId. Returns the payload if the entry existed, or None otherwise.

Source

fn range_query(&self, bbox: &BBox<C, D>) -> Vec<(EntryId, &T)>

Return all entries whose positions are contained within bbox.

Source

fn knn_query(&self, point: &Point<C, D>, k: usize) -> Vec<(f64, EntryId, &T)>

Return the k nearest entries to point, ordered by ascending Euclidean distance. Each result is (distance, id, payload_ref).

Source

fn spatial_join( &self, other: &dyn SpatialBackend<T, C, D>, ) -> Vec<(EntryId, EntryId)>

Return all pairs (id_a, id_b) where the bounding box of entry id_a in self intersects the bounding box of entry id_b in other.

For point-only backends the “bounding box” of a point is the degenerate box [p, p].

Source

fn bulk_load(entries: Vec<(Point<C, D>, T)>) -> Self
where Self: Sized,

Bulk-load a set of (point, payload) pairs into a new backend instance.

Implementations may sort entries (e.g. by Hilbert index) for better spatial locality.

Source

fn len(&self) -> usize

Return the number of entries currently stored.

Source

fn kind(&self) -> BackendKind

Return the BackendKind discriminant for this backend.

Source

fn all_entries(&self) -> Vec<(Point<C, D>, EntryId, &T)>

Return all (point, id, payload) triples — used by spatial_join implementations that need to iterate over the other backend’s entries.

Provided Methods§

Source

fn is_empty(&self) -> bool

Return true if the backend contains no entries.

Implementors§

Source§

impl<T: Send + Sync + 'static, C: CoordType, const D: usize> SpatialBackend<T, C, D> for GridIndex<T, C, D>

Source§

impl<T: Send + Sync + 'static, C: CoordType, const D: usize> SpatialBackend<T, C, D> for KDTree<T, C, D>

Source§

impl<T: Send + Sync + 'static, C: CoordType, const D: usize> SpatialBackend<T, C, D> for Quadtree<T, C, D>

Source§

impl<T: Send + Sync + 'static, C: CoordType, const D: usize> SpatialBackend<T, C, D> for RTree<T, C, D>