Module kdtree

Source
Expand description

An immutable, ABI-stable K-D Tree.

§Creation

Use KDTreeBuilder to construct an KDTree, which allows you to make queries.

§Search

Use KDTreeIndex::range to search a KDTree given a bounding box query. Use KDTreeIndex::within to search a KDTree given a point and radius.

§Persisting

You can use KDTree::into_inner to access the underlying Vec<u8> it contains.

§Recovering the index

You can use KDTreeRef::try_new to construct a KDTree as a reference on an external byte slice. If you don’t know the coordinate type used in the index, you can use CoordType::from_buffer to infer the coordinate type.

§Coordinate types

Supported coordinate types implement IndexableNum. Note that float NaN is not supported and may panic.

§Example

use geo_index::kdtree::{KDTreeBuilder, KDTreeIndex, KDTreeRef};

// Create a KDTree
let mut builder = KDTreeBuilder::<f64>::new(3);
builder.add(0., 0.);
builder.add(1., 1.);
builder.add(2., 2.);
let tree = builder.finish();

// Perform a search
assert_eq!(tree.range(0.5, 0.5, 1.5, 1.5), vec![1]);

// Convert to underlying buffer
let buffer = tree.into_inner();

// Create tree as a reference onto this buffer
let tree_ref = KDTreeRef::<f64>::try_new(&buffer).unwrap();

// Perform search again
assert_eq!(tree_ref.range(0.5, 0.5, 1.5, 1.5), vec![1]);

Structs§

KDTree
An owned KDTree buffer.
KDTreeBuilder
A builder to create an KDTree.
KDTreeMetadata
Common metadata to describe a KDTree
KDTreeRef
A reference on an external KDTree buffer.
Node
An internal node in the KDTree.

Constants§

DEFAULT_KDTREE_NODE_SIZE
Default node size in KDTreeBuilder::new.

Traits§

KDTreeIndex
A trait for searching and accessing data out of a KDTree.