Skip to main content

ArchivedKdTree

Struct ArchivedKdTree 

Source
pub struct ArchivedKdTree<A: Copy + Default, T, const K: usize, const B: usize, IDX>
where Vec<LeafNode<A, T, K, B, IDX>>: Archive, Vec<StemNode<A, K, IDX>>: Archive, IDX: Archive, T: Archive + Copy + Default,
{ /* private fields */ }
Expand description

An archived KdTree

Implementations§

Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn size(&self) -> T

Returns the current number of elements stored in the tree

§Examples
use kiddo::KdTree;

let mut tree: KdTree<f64, 3> = KdTree::new();

tree.add(&[1.0, 2.0, 5.0], 100);
tree.add(&[1.1, 2.1, 5.1], 101);

assert_eq!(tree.size(), 2);
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn best_n_within<D>( &self, query: &[A; K], dist: A, max_qty: usize, ) -> impl Iterator<Item = BestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds the “best” n elements within dist of query.

Results are returned in arbitrary order. ‘Best’ is determined by performing a comparison of the elements using < (ie, std::cmp::Ordering::is_lt). Returns an iterator. Returns an iterator.

§Examples
    use kiddo::KdTree;
    use kiddo::best_neighbour::BestNeighbour;
    use kiddo::SquaredEuclidean;

    use std::fs::File;
    use memmap::MmapOptions;

    let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
    let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

    let mut best_n_within = tree.best_n_within::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64, 1);
    let first = best_n_within.next().unwrap();

    assert_eq!(first, BestNeighbour { distance: 0.0, item: 100 });
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn nearest_n<D>( &self, query: &[A; K], qty: usize, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds the nearest qty elements to query, using the specified distance metric function.

§Examples
    use kiddo::KdTree;
    use kiddo::SquaredEuclidean;

    use std::fs::File;
    use memmap::MmapOptions;

    let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
    let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

    let nearest: Vec<_> = tree.nearest_n::<SquaredEuclidean>(&[1.0, 2.0, 5.1], 1);

    assert_eq!(nearest.len(), 1);
    assert!((nearest[0].distance - 0.01f64).abs() < f64::EPSILON);
    assert_eq!(nearest[0].item, 100);
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn nearest_n_within<D>( &self, query: &[A; K], dist: A, max_items: NonZero<usize>, sorted: bool, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds up to n elements within dist of query, using the specified distance metric function.

Results are returned in as a ResultCollection, which can return a sorted or unsorted Vec.

§Examples
use std::num::NonZero;
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };
let max_qty = NonZero::new(1).unwrap();
let within = tree.nearest_n_within::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64, max_qty, true);

assert_eq!(within.len(), 1);
Source

pub fn nearest_n_within_exclusive<D>( &self, query: &[A; K], dist: A, max_items: NonZero<usize>, sorted: bool, inclusive: bool, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds up to n elements within dist of query, using the specified distance metric function.

Results are returned in as a ResultCollection, which can return a sorted or unsorted Vec.

§Examples
use std::num::NonZero;
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };
let max_qty = NonZero::new(1).unwrap();
let within = tree.nearest_n_within::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64, max_qty, true);

assert_eq!(within.len(), 1);
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn nearest_one<D>(&self, query: &[A; K]) -> NearestNeighbour<A, T>
where D: DistanceMetric<A, K>,

Finds the nearest element to query, using the specified distance metric function.

Faster than querying for nearest_n(point, 1, …) due to not needing to allocate memory or maintain sorted results.

§Examples
    use kiddo::KdTree;
    use kiddo::SquaredEuclidean;

    use std::fs::File;
    use memmap::MmapOptions;

    let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
    let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

    let nearest = tree.nearest_one::<SquaredEuclidean>(&[1.0, 2.0, 5.1]);

    assert!((nearest.distance - 0.01f64).abs() < f64::EPSILON);
    assert_eq!(nearest.item, 100);
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn within<D>(&self, query: &[A; K], dist: A) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Results are returned sorted nearest-first

§Examples
    use kiddo::KdTree;
    use kiddo::SquaredEuclidean;
    use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

    let within = tree.within::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64);

    assert_eq!(within.len(), 2);
Source

pub fn within_exclusive<D>( &self, query: &[A; K], dist: A, inclusive: bool, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Results are returned sorted nearest-first

§Examples
    use kiddo::KdTree;
    use kiddo::SquaredEuclidean;
    use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

    let within = tree.within::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64);

    assert_eq!(within.len(), 2);
Source§

impl<A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX>> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn within_unsorted<D>( &self, query: &[A; K], dist: A, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Results are returned in arbitrary order. Faster than within.

§Examples
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

let within = tree.within_unsorted::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64);

assert_eq!(within.len(), 2);
Source

pub fn within_unsorted_exclusive<D>( &self, query: &[A; K], dist: A, inclusive: bool, ) -> Vec<NearestNeighbour<A, T>>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Results are returned in arbitrary order. Faster than within.

§Examples
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

let within = tree.within_unsorted::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64);

assert_eq!(within.len(), 2);
Source§

impl<'a, 'query, A: Axis + Archive<Archived = A>, T: Content + Archive<Archived = T>, const K: usize, const B: usize, IDX: Index<T = IDX> + Archive<Archived = IDX> + Send> ArchivedKdTree<A, T, K, B, IDX>
where usize: Cast<IDX>,

Source

pub fn within_unsorted_iter<D>( &'a self, query: &'query [A; K], dist: A, ) -> WithinUnsortedIter<'a, A, T>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Returns an Iterator. Results are returned in arbitrary order.

§Examples
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

let within = tree.within_unsorted_iter::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64).collect::<Vec<_>>();

assert_eq!(within.len(), 2);
Source

pub fn within_unsorted_iter_exclusive<D>( &'a self, query: &'query [A; K], dist: A, inclusive: bool, ) -> WithinUnsortedIter<'a, A, T>
where D: DistanceMetric<A, K>,

Finds all elements within dist of query, using the specified distance metric function.

Returns an Iterator. Results are returned in arbitrary order.

§Examples
use kiddo::KdTree;
use kiddo::SquaredEuclidean;
use std::fs::File;
use memmap::MmapOptions;

let mmap = unsafe { MmapOptions::new().map(&File::open("./examples/float-doctest-tree.rkyv").expect("./examples/float-doctest-tree.rkyv missing")).unwrap() };
let tree = unsafe { rkyv::archived_root::<KdTree<f64, 3>>(&mmap) };

let within = tree.within_unsorted_iter::<SquaredEuclidean>(&[1.0, 2.0, 5.0], 10f64).collect::<Vec<_>>();

assert_eq!(within.len(), 2);

Auto Trait Implementations§

§

impl<A, T, const K: usize, const B: usize, IDX> !Freeze for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !RefUnwindSafe for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !Send for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !Sync for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !Unpin for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !UnsafeUnpin for ArchivedKdTree<A, T, K, B, IDX>

§

impl<A, T, const K: usize, const B: usize, IDX> !UnwindSafe for ArchivedKdTree<A, T, K, B, IDX>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.