### Rust Standard Library and Tools Source: https://docs.rs/space/0.19.0/src/space/lib.rs Provides links to essential Rust resources, including the official Rust website, The Book, Standard Library API Reference, Rust by Example, the Cargo Guide, and Clippy documentation. ```Rust Rust Resources: - Rust website: https://www.rust-lang.org/ - The Book: https://doc.rust-lang.org/book/ - Standard Library API Reference: https://doc.rust-lang.org/std/ - Rust by Example: https://doc.rust-lang.org/rust-by-example/ - The Cargo Guide: https://doc.rust-lang.org/cargo/guide/ - Clippy Documentation: https://doc.rust-lang.org/nightly/clippy ``` -------------------------------- ### Metric Trait Implementation Example Source: https://docs.rs/space/0.19.0/space/trait.Metric An example implementation of the `Metric` trait for a custom `AbsDiff` type. This implementation calculates the absolute difference between two `f64` values and returns it as a `u64` by converting the float's bits. It includes a debug assertion to ensure the distance is not NaN. ```rust use pgat::ReferenceProxy; #[derive(Copy, Clone, Default)] struct AbsDiff; impl space::Metric> for AbsDiff { type Unit = u64; fn distance(&self, &a: &f64, &b: &f64) -> Self::Unit { let delta = (a - b).abs(); debug_assert!(!delta.is_nan()); delta.to_bits() } } ``` -------------------------------- ### Rust space Crate Overview Source: https://docs.rs/space/0.19.0/space/all Provides an overview of the 'space' crate, including its purpose, license, source, and dependencies. It lists available platforms and feature flags. ```rust Project: /context7/rs-space-0.19.0 Content: [ Docs.rs ](https://docs.rs/) * [ space-0.19.0 ](https://docs.rs/space/0.19.0/space/all.html "A library providing abstractions for spatial datastructures and search") * space 0.19.0 * [ ](https://docs.rs/crate/space/0.19.0 "See space in docs.rs") * [MIT](https://spdx.org/licenses/MIT) * Links * [ ](https://github.com/rust-cv/space) * [ ](https://crates.io/crates/space "See space in crates.io") * [ ](https://docs.rs/crate/space/0.19.0/source/ "Browse source of space-0.19.0") * Owners * [ ](https://crates.io/users/vadixidav) * Dependencies * * [ doc-comment ^0.3.3 _normal_ ](https://docs.rs/doc-comment/^0.3.3) * [ num-traits ^0.2.19 _normal_ ](https://docs.rs/num-traits/^0.2.19) * [ pgat ^0.3.0 _normal_ ](https://docs.rs/pgat/^0.3.0) * [ criterion ^0.7.0 _dev_ ](https://docs.rs/criterion/^0.7.0) * [ decorum ^0.4.0 _dev_ ](https://docs.rs/decorum/^0.4.0) * [ ndarray ^0.16.1 _dev_ ](https://docs.rs/ndarray/^0.16.1) * [ rand_core ^0.9.3 _dev_ ](https://docs.rs/rand_core/^0.9.3) * [ rand_pcg ^0.9.0 _dev_ ](https://docs.rs/rand_pcg/^0.9.0) * Versions * [ **54.29%** of the crate is documented ](https://docs.rs/crate/space/0.19.0) * [ Platform ](https://docs.rs/space/0.19.0/space/all.html) * [i686-pc-windows-msvc](https://docs.rs/crate/space/0.19.0/target-redirect/i686-pc-windows-msvc/space/all.html) * [i686-unknown-linux-gnu](https://docs.rs/crate/space/0.19.0/target-redirect/i686-unknown-linux-gnu/space/all.html) * [x86_64-apple-darwin](https://docs.rs/crate/space/0.19.0/target-redirect/x86_64-apple-darwin/space/all.html) * [x86_64-pc-windows-msvc](https://docs.rs/crate/space/0.19.0/target-redirect/x86_64-pc-windows-msvc/space/all.html) * [x86_64-unknown-linux-gnu](https://docs.rs/crate/space/0.19.0/target-redirect/x86_64-unknown-linux-gnu/space/all.html) * [ Feature flags ](https://docs.rs/crate/space/0.19.0/features "Browse available feature flags of space-0.19.0") * [docs.rs](https://docs.rs/space/0.19.0/space/all.html) * [](https://docs.rs/about) * [](https://docs.rs/about/badges) * [](https://docs.rs/about/builds) * [](https://docs.rs/about/metadata) * [](https://docs.rs/about/redirections) * [](https://docs.rs/about/download) * [](https://docs.rs/about/rustdoc-json) * [](https://docs.rs/releases/queue) * [](https://foundation.rust-lang.org/policies/privacy-policy/#docs.rs) * [Rust](https://docs.rs/space/0.19.0/space/all.html) * [Rust website](https://www.rust-lang.org/) * [The Book](https://doc.rust-lang.org/book/) * [Standard Library API Reference](https://doc.rust-lang.org/std/) * [Rust by Example](https://doc.rust-lang.org/rust-by-example/) * [The Cargo Guide](https://doc.rust-lang.org/cargo/guide/) * [Clippy Documentation](https://doc.rust-lang.org/nightly/clippy) ``` -------------------------------- ### Knn Trait for Nearest Neighbor Search Source: https://docs.rs/space/0.19.0/src/space/lib.rs The `Knn` trait defines the interface for data structures that perform k-nearest neighbor searches. Implementors must provide a way to retrieve a specified number of nearest neighbors to a given query point, sorted by distance. The `nn` method is a convenience function to get the single nearest neighbor. ```rust pub trait Knn: ApproximateSpace { type KnnIter<'a>: Iterator, View<'a, Self::PointProxy>, View<'a, Self::ValueProxy>)> where Self: 'a; /// Get `num` nearest neighbors' distance, key, and value relative to the `target` position. /// /// The neighbors must be sorted by distance, with the closest neighbor first. fn knn<'a, 'b>(&'a self, query: View<'b, Self::PointProxy>, num: usize) -> Self::KnnIter<'a>; /// Get the nearest neighbor's distance, key, and value relative to the `target` position. #[allow(clippy::type_complexity)] fn nn<'a, 'b>( &'a self, query: View<'b, Self::PointProxy>, ) -> Option<( MetricUnit, View<'a, Self::PointProxy>, View<'a, Self::ValueProxy>, )> { self.knn(query, 1).next() } } ``` -------------------------------- ### Rustdoc Keyboard Shortcuts Source: https://docs.rs/space/0.19.0/help Provides a list of keyboard shortcuts for interacting with the rustdoc documentation interface. These shortcuts allow for quick navigation, searching, and expanding/collapsing content sections. ```rust `?` Show this help dialog `S` / `/` Focus the search field `↑` Move up in search results `↓` Move down in search results `←` / `→` Switch result tab (when results focused) `⏎` Go to active search result `+` Expand all sections `-` Collapse all sections `_` Collapse all sections, including impl blocks ``` -------------------------------- ### Rust space Crate Overview Source: https://docs.rs/space/0.19.0/space/trait.ExactSpace General information about the Rust 'space' crate, including its purpose, version, and links to external resources. ```APIDOC Project: /context7/rs-space-0.19.0 Crate: space Version: 0.19.0 Description: A library providing abstractions for spatial datastructures and search License: MIT Repository: https://github.com/rust-cv/space Documentation: https://docs.rs/space/0.19.0/space/ Crates.io: https://crates.io/crates/space Dependencies: - doc-comment ^0.3.3 - num-traits ^0.2.19 - pgat ^0.3.0 Dev Dependencies: - criterion ^0.7.0 - decorum ^0.4.0 - ndarray ^0.16.1 - rand_core ^0.9.3 - rand_pcg ^0.9.0 Documentation Coverage: 54.29% Supported Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu ``` -------------------------------- ### Rust Crate Information: space v0.19.0 Source: https://docs.rs/space/0.19.0/src/space/lib.rs Provides an overview of the 'space' Rust crate, including its version, license, source repository, and dependencies. It also indicates the percentage of the crate that is documented. ```Rust Crate: space Version: 0.19.0 License: MIT Repository: https://github.com/rust-cv/space Documentation: https://docs.rs/space/0.19.0/ Dependencies: - doc-comment ^0.3.3 - num-traits ^0.2.19 - pgat ^0.3.0 Development Dependencies: - criterion ^0.7.0 - decorum ^0.4.0 - ndarray ^0.16.1 - rand_core ^0.9.3 - rand_pcg ^0.9.0 Documentation Coverage: 54.29% ``` -------------------------------- ### LinearSearch Constructor Source: https://docs.rs/space/0.19.0/src/space/linear.rs Provides a constructor function `new` for creating instances of `LinearSearch`. It takes a metric and a slice of data points as input and initializes the struct with these values. ```rust impl<'a, M, P, V, PP, VP> where M: Metric, PP: ProxyView, VP: ProxyView, { pub fn new(metric: M, data: &'a [(P, V)]) -> Self { Self { metric, data, _phantom: core::marker::PhantomData, } } } ``` -------------------------------- ### Rustdoc Settings Source: https://docs.rs/space/0.19.0/settings This section details the available settings for Rustdoc, the documentation generator for Rust. It includes options for theme selection, auto-hiding content, search behavior, code display, and navigation. ```rust Theme light dark ayu system preference Preferred light theme light dark ayu Preferred dark theme light dark ayu Auto-hide item contents for large items Auto-hide item methods' documentation Auto-hide trait implementation documentation Directly go to item in search if there is only one result Show line numbers on code examples Hide persistent navigation bar Hide table of contents Hide module navigation Disable keyboard shortcuts Use sans serif fonts Word wrap source code ``` -------------------------------- ### Rust space Crate Items Source: https://docs.rs/space/0.19.0/space/all Lists the main items available in the 'space' crate, categorized into Structs, Traits, Functions, and Type Aliases. Each item links to its detailed documentation. ```rust # List of all items ### Structs * [LinearContainer](https://docs.rs/space/0.19.0/space/struct.LinearContainer.html) * [LinearSearch](https://docs.rs/space/0.19.0/space/struct.LinearSearch.html) ### Traits * [ApproximateSpace](https://docs.rs/space/0.19.0/space/trait.ApproximateSpace.html) * [ExactSpace](https://docs.rs/space/0.19.0/space/trait.ExactSpace.html) * [Knn](https://docs.rs/space/0.19.0/space/trait.Knn.html) * [Metric](https://docs.rs/space/0.19.0/space/trait.Metric.html) * [NSphereRangeQuery](https://docs.rs/space/0.19.0/space/trait.NSphereRangeQuery.html) * [SpatialContainer](https://docs.rs/space/0.19.0/space/trait.SpatialContainer.html) ### Functions * [linear_knn](https://docs.rs/space/0.19.0/space/fn.linear_knn.html) * [linear_nn](https://docs.rs/space/0.19.0/space/fn.linear_nn.html) ### Type Aliases * [MetricUnit](https://docs.rs/space/0.19.0/space/type.MetricUnit.html) ``` -------------------------------- ### Supported Platforms for space Crate Source: https://docs.rs/space/0.19.0/src/space/lib.rs Lists the platforms for which the 'space' Rust crate has been compiled and tested, as indicated by the documentation. This helps users understand compatibility. ```Rust Supported Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu ``` -------------------------------- ### LinearSearch Struct Documentation Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `LinearSearch` struct, which implements linear search algorithms for spatial data. ```APIDOC LinearSearch: Methods: new() -> Self Creates a new `LinearSearch` instance. search(&self, container: &LinearContainer, query: &T) -> Option Performs a linear search for a query item within a `LinearContainer`. Parameters: container: The `LinearContainer` to search within. query: The item to search for. Returns: An `Option` containing the index of the item if found, otherwise `None`. ``` -------------------------------- ### Rustdoc Search Tricks Source: https://docs.rs/space/0.19.0/help Explains advanced search functionalities within rustdoc, enabling users to refine their searches by item kind, type signature, exact names, and paths. ```rust Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given item kind. Accepted kinds are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `-> vec` or `String, enum:Cow -> bool`) You can look for items with an exact name by putting double quotes around your request: `"string"` Look for functions that accept or return [slices](https://doc.rust-lang.org/nightly/std/primitive.slice.html) and [arrays](https://doc.rust-lang.org/nightly/std/primitive.array.html) by writing square brackets (e.g., `-> [u8]` or `[] -> Option`) Look for items inside another one by searching for a path: `vec::Vec` ``` -------------------------------- ### Knn Trait Documentation Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `Knn` trait, a general interface for k-nearest neighbors search in spatial data structures. ```APIDOC Knn: Methods: knn(&self, point: &Self::Unit, k: usize) -> Vec<(Self::Unit, f64)> Performs a k-nearest neighbors search. Parameters: point: The query point. k: The number of nearest neighbors to find. Returns: A vector of tuples, where each tuple contains a neighbor and its distance. ``` -------------------------------- ### Linear KNN Function Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `linear_knn` function, which performs a linear k-nearest neighbors search. ```APIDOC linear_knn(container: &LinearContainer, point: &T, k: usize) -> Vec<(T, f64)> Performs a linear k-nearest neighbors search. Parameters: container: The `LinearContainer` to search within. point: The query point. k: The number of nearest neighbors to find. Returns: A vector of tuples, where each tuple contains a neighbor and its distance. ``` -------------------------------- ### Space Crate Supported Platforms Source: https://docs.rs/space/0.19.0/src/space/linear.rs Details the platforms for which the 'space' crate has been built and tested. ```rust /// Platform: /// * i686-pc-windows-msvc /// * i686-unknown-linux-gnu /// * x86_64-apple-darwin /// * x86_64-pc-windows-msvc /// * x86_64-unknown-linux-gnu ``` -------------------------------- ### Space Crate API Documentation Source: https://docs.rs/space/0.19.0/space/fn.linear_knn API documentation for the Rust 'space' crate, version 0.19.0. This includes definitions for structs, traits, and functions related to spatial data structures and search. ```APIDOC Structs: LinearContainer: A container for linear data. LinearSearch: A structure for performing linear searches. Traits: ApproximateSpace: Trait for approximate spatial search algorithms. ExactSpace: Trait for exact spatial search algorithms. Knn: Trait for k-nearest neighbors search functionality. Metric: Trait for defining distance or similarity metrics. NSphereRangeQuery: Trait for n-sphere range queries. SpatialContainer: Trait for spatial data containers. Functions: linear_knn(container: &impl SpatialContainer, query: T, k: usize, metric: &M) -> Vec<(T, usize)> where T: Clone, M: Metric Performs a linear k-nearest neighbors search. Parameters: container: The spatial data container. query: The point to search around. k: The number of nearest neighbors to find. metric: The metric to use for distance calculation. Returns: A vector of tuples, where each tuple contains a neighbor and its index. linear_nn(container: &impl SpatialContainer, query: T, metric: &M) -> Option<(T, usize)> where T: Clone, M: Metric Performs a linear nearest neighbor search. Parameters: container: The spatial data container. query: The point to search around. metric: The metric to use for distance calculation. Returns: An Option containing a tuple of the nearest neighbor and its index, or None if the container is empty. ``` -------------------------------- ### Space Crate Dependencies Source: https://docs.rs/space/0.19.0/src/space/linear.rs Lists the development and normal dependencies for the 'space' crate version 0.19.0. ```rust /// Dependencies: /// * doc-comment ^0.3.3 _normal_ /// * num-traits ^0.2.19 _normal_ /// * pgat ^0.3.0 _normal_ /// * criterion ^0.7.0 _dev_ /// * decorum ^0.4.0 _dev_ /// * ndarray ^0.16.1 _dev_ /// * rand_core ^0.9.3 _dev_ /// * rand_pcg ^0.9.0 _dev_ ``` -------------------------------- ### Knn Trait API Documentation Source: https://docs.rs/space/0.19.0/space/trait.Knn API documentation for the `Knn` trait, including its associated types and methods for nearest neighbor search. This covers the `knn` and `nn` methods, their parameters, return values, and the `KnnIter` associated type. ```APIDOC Knn Trait: Associated Types: KnnIter<'a>: Iterator, View<'a, Self::PointProxy>, View<'a, Self::ValueProxy>)> Required Methods: knn<'a, 'b>( &self, query: View<'b, Self::PointProxy>, num: usize ) -> Self::KnnIter<'a> - Get `num` nearest neighbors’ distance, key, and value relative to the `target` position. - The neighbors must be sorted by distance, with the closest neighbor first. Provided Methods: nn<'a, 'b>( &self, query: View<'b, Self::PointProxy> ) -> Option<(MetricUnit, View<'a, Self::PointProxy>, View<'a, Self::ValueProxy>)> - Get the nearest neighbor’s distance, key, and value relative to the `target` position. Dyn Compatibility: This trait is not dyn compatible. Implementors: impl<'c, M, P, V, PP, VP> Knn for LinearSearch<'c, M, P, V, PP, VP> where M: Metric, PP: ProxyView, VP: ProxyView ``` -------------------------------- ### LinearSearch Constructor Source: https://docs.rs/space/0.19.0/space/struct.LinearSearch The `new` function is a public associated function for LinearSearch that constructs a new instance. It takes a metric and a slice of data as input. ```rust pub fn new(metric: M, data: &'a [(P, V)]) -> Self ``` -------------------------------- ### Space Crate Overview Source: https://docs.rs/space/0.19.0/src/space/linear.rs Provides abstractions for spatial data structures and search. This crate is licensed under MIT. ```rust /// A library providing abstractions for spatial datastructures and search /// Licensed under MIT ``` -------------------------------- ### LinearContainer Struct Documentation Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `LinearContainer` struct, a simple linear data structure for spatial data. ```APIDOC LinearContainer: Fields: data: Vec A vector holding the spatial data. Methods: new() -> Self Creates a new, empty `LinearContainer`. insert(&mut self, item: T) Inserts an item into the container. remove(&mut self, item: &T) -> bool Removes an item from the container. ``` -------------------------------- ### Rust Space Crate API Documentation Source: https://docs.rs/space/0.19.0/space/struct.LinearSearch API documentation for the Rust space crate, version 0.19.0. This section covers the `Knn` trait and its associated types and methods, specifically focusing on the `knn` and `nn` functions for nearest neighbor searches within a linear search implementation. ```APIDOC KnnIter<'a>: An iterator type for nearest neighbor search results. Associated with the Knn trait. Type alias for `IntoIter` of specific data types. knn<'a, 'b>(query: View<'b, Self::PointProxy>, num: usize) -> Self::KnnIter<'a> - Description: Get `num` nearest neighbors’ distance, key, and value relative to the `target` position. - Parameters: - query: A view of the query point, using the space's PointProxy. - num: The number of nearest neighbors to retrieve. - Returns: An iterator over the nearest neighbors. nn<'a, 'b>(query: View<'b, Self::PointProxy>) -> Option<(M::Unit, View<'a, PP>, View<'a, VP>)> - Description: Get the nearest neighbor’s distance, key, and value relative to the `target` position. - Parameters: - query: A view of the query point, using the space's PointProxy. - Returns: An Option containing a tuple of the nearest neighbor's distance, key, and value, or None if no neighbor is found. ExactSpace for LinearSearch<'a, M, P, V, PP, VP>: - Description: Implemented for linear search, which is an exact search algorithm. - Constraints: - M: Metric - PP: ProxyView - VP: ProxyView Freeze for LinearSearch<'a, M, P, V, PP, VP>: - Description: Auto trait implementation for Freeze. - Constraints: - M: Freeze ``` -------------------------------- ### Space Crate Structs Source: https://docs.rs/space/0.19.0/space/trait.NSphereRangeQuery Documentation for key structs within the Rust 'space' crate, including LinearContainer and LinearSearch. These structs are fundamental components for implementing spatial data structures and search algorithms. ```APIDOC Structs in space crate: LinearContainer: A data structure for linear storage of spatial data. LinearSearch: An implementation of a linear search algorithm for spatial data. ``` -------------------------------- ### LinearContainer Methods (Rust) Source: https://docs.rs/space/0.19.0/src/space/linear.rs Implements core methods for the LinearContainer, including initialization with a metric, inserting data points with associated values, and providing an iterator over the spatial data. It defines the structure for spatial iteration. ```rust impl LinearContainer where M: Metric, PP: ProxyView, VP: ProxyView, { type SpatialIter<'a> = Map, fn(&'a (P, V)) -> (View<'a, PP>, View<'a, VP>)>; fn with_metric(metric: Self::Metric) -> Self { Self { metric, data: Vec::new(), _phantom: core::marker::PhantomData, } } fn insert(&mut self, point: P, value: V) { self.data.push((point, value)); } fn iter(&self) -> Self::SpatialIter<'_> { self.data.iter().map(|(p, v)| (PP::view(p), VP::view(v))) } } ``` -------------------------------- ### Functions in space Crate Source: https://docs.rs/space/0.19.0/space/trait.ExactSpace Documentation for the functions available in the 'space' crate. These functions likely provide utility or specific spatial algorithms. ```APIDOC Functions: - [linear_knn](https://docs.rs/space/0.19.0/space/fn.linear_knn.html) - [linear_nn](https://docs.rs/space/0.19.0/space/fn.linear_nn.html) ``` -------------------------------- ### Knn Trait Documentation Source: https://docs.rs/space/0.19.0/space/trait.Knn Documentation for the Knn trait in the 'space' crate. This trait defines methods for k-nearest neighbor searches within spatial data structures. It includes required associated types and methods, as well as provided methods and dynamic compatibility information. ```APIDOC Knn Trait: Associated Types: - KnnIter: Iterator type for k-nearest neighbor results. Methods: - knn(query: &Q, k: usize) -> Self::KnnIter Finds the k nearest neighbors to a given query point. Parameters: - query: The point to search around. - k: The number of nearest neighbors to find. Returns: An iterator over the k nearest neighbors. - nn(query: &Q) -> Option Finds the nearest neighbor to a given query point. Parameters: - query: The point to search around. Returns: An Option containing an iterator to the nearest neighbor, or None if no neighbors are found. ``` -------------------------------- ### ExactSpace Trait Documentation Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `ExactSpace` trait, providing exact search capabilities for spatial data structures. ```APIDOC ExactSpace: Inherits from: Metric Methods: exact_knn(&self, point: &Self::Unit, k: usize) -> Vec<(Self::Unit, f64)> Performs an exact k-nearest neighbors search. Parameters: point: The query point. k: The number of nearest neighbors to find. Returns: A vector of tuples, where each tuple contains a neighbor and its distance. ``` -------------------------------- ### Spatial Search Functions Source: https://docs.rs/space/0.19.0/space/trait.Knn Documentation for spatial search functions provided by the 'space' crate. These functions likely implement specific search algorithms. ```APIDOC Functions: - linear_knn(data: &[T], query: &T, k: usize) -> Vec<(usize, T)> Performs a linear k-nearest neighbor search on a slice of data. Parameters: - data: A slice of data points. - query: The point to search around. - k: The number of nearest neighbors to find. Returns: A vector of tuples, where each tuple contains the index and the data point of a nearest neighbor. - linear_nn(data: &[T], query: &T) -> Option<(usize, T)> Performs a linear nearest neighbor search on a slice of data. Parameters: - data: A slice of data points. - query: The point to search around. Returns: An Option containing a tuple with the index and data point of the nearest neighbor, or None if the data is empty. ``` -------------------------------- ### LinearSearch Implementations (Blanket Traits) Source: https://docs.rs/space/0.19.0/space/struct.LinearSearch Details the blanket trait implementations for the LinearSearch struct, showcasing its compatibility with standard Rust traits. These include Any, Borrow, BorrowMut, From, Into, TryFrom, and TryInto. ```APIDOC Blanket Implementations for LinearSearch: - Any - Borrow - BorrowMut - From - Into - TryFrom - TryInto ``` -------------------------------- ### NSphereRangeQuery Trait Documentation Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `NSphereRangeQuery` trait, enabling search for points within a specified n-sphere (radius). ```APIDOC NSphereRangeQuery: Methods: n_sphere_range_query(&self, point: &Self::Unit, radius: f64) -> Vec<(Self::Unit, f64)> Finds all points within a given radius of a query point. Parameters: point: The center of the n-sphere. radius: The radius of the n-sphere. Returns: A vector of tuples, where each tuple contains a point within the radius and its distance. ``` -------------------------------- ### Find Nearest Neighbor in Dataset Source: https://docs.rs/space/0.19.0/src/space/lib.rs This snippet demonstrates how to find the nearest neighbor to a query point within a dataset. It maps each data point to its distance from the query, then finds the minimum distance entry. This is useful for k-NN search or similarity calculations. ```rust let (pt, val) = dataset .map(|(pt, val)| (metric.distance(pt, query), pt, val)) .min_by_key(|n| n.0); ``` -------------------------------- ### LinearContainer Methods: knn and nn Source: https://docs.rs/space/0.19.0/src/space/linear.rs Implements k-nearest neighbors (knn) and nearest neighbor (nn) search functionalities for the LinearContainer. The knn method returns an iterator over the k nearest neighbors, while nn returns the single nearest neighbor. These methods rely on helper functions `linear_knn` and `linear_nn` respectively. ```rust impl<'a, 'b, M, P, V, PP, VP> LinearContainer where M: Metric, PP: ProxyView, VP: ProxyView, { /// Finds the k nearest neighbors to a query point. /// /// # Arguments /// /// * `query` - The point to search around. /// * `num` - The number of neighbors to find. /// /// # Returns /// /// An iterator over the k nearest neighbors. fn knn<'a, 'b>(&'a self, query: View<'b, Self::PointProxy>, num: usize) -> Self::KnnIter<'a> { linear_knn::( self.metric, self.data .iter() .map(|(pt, val)| (PP::view(pt), VP::view(val))), query, num, ) .into_iter() } /// Finds the nearest neighbor to a query point. /// /// # Arguments /// /// * `query` - The point to search around. /// /// # Returns /// /// An Option containing the nearest neighbor's distance, point proxy, and value proxy. fn nn<'a, 'b>( &'a self, query: View<'b, Self::PointProxy>, ) -> Option<(M::Unit, View<'a, PP>, View<'a, VP>)> { linear_nn::( self.metric, self.data .iter() .map(|(pt, val)| (PP::view(pt), VP::view(val))), query, ) } } ``` -------------------------------- ### LinearContainer Blanket Implementations Source: https://docs.rs/space/0.19.0/space/struct.LinearContainer Details the blanket implementations for generic types T within the LinearContainer context. These include Any, Borrow, BorrowMut, From, Into, TryFrom, and TryInto, enabling flexible type conversions and borrowing. ```rust // Blanket Implementations for T in the context of LinearContainer // impl Any for T // impl Borrow for T // impl BorrowMut for T // impl From for T // impl Into for T // impl TryFrom for T // impl TryInto for T ``` -------------------------------- ### Linear Search Functions Source: https://docs.rs/space/0.19.0/space Functions for performing exact linear nearest neighbor searches. ```rust fn linear_knn(...) -> ... fn linear_nn(...) -> ... ``` -------------------------------- ### Space Crate Traits Source: https://docs.rs/space/0.19.0/space/trait.Knn Overview of the core traits provided by the 'space' crate for spatial data management and querying. ```APIDOC Traits: - ApproximateSpace: Trait for data structures that support approximate spatial queries. - ExactSpace: Trait for data structures that support exact spatial queries. - Knn: Trait for data structures that support k-nearest neighbor queries (see Knn Trait Documentation). - Metric: Trait for defining distance or similarity metrics between data points. - NSphereRangeQuery: Trait for performing range queries within a specified hypersphere. - SpatialContainer: A fundamental trait for any spatial data structure within the crate. ``` -------------------------------- ### Linear Container and Search Structures Source: https://docs.rs/space/0.19.0/space/trait.Knn Documentation for LinearContainer and LinearSearch structs in the 'space' crate. These structures are likely used for basic, non-optimized spatial indexing or searching. ```APIDOC Structs: - LinearContainer: A basic container for spatial data, likely for linear access. - LinearSearch: A structure implementing linear search algorithms for spatial data. Dependencies: Requires the 'space' crate itself. Usage: Typically used for straightforward, brute-force nearest neighbor searches. ``` -------------------------------- ### Space Crate - Functions Source: https://docs.rs/space/0.19.0/space/struct.LinearSearch Lists the functions available in the 'space' crate, providing utility for spatial search operations. These include functions for performing k-nearest neighbor and nearest neighbor searches using linear methods. ```APIDOC Functions in the 'space' crate: - linear_knn - linear_nn ``` -------------------------------- ### Linear NN Function Source: https://docs.rs/space/0.19.0/space/trait.Metric Documentation for the `linear_nn` function, which finds the nearest neighbor to a query point using linear search. ```APIDOC linear_nn(container: &LinearContainer, point: &T) -> Option<(T, f64)> Finds the nearest neighbor to a query point using linear search. Parameters: container: The `LinearContainer` to search within. point: The query point. Returns: An `Option<(T, f64)>` containing the nearest neighbor and its distance if found, otherwise `None`. ``` -------------------------------- ### Linear Search Functions Source: https://docs.rs/space/0.19.0/index Functions for performing exact linear nearest neighbor searches. ```rust fn linear_knn(...) -> ... fn linear_nn(...) -> ... ``` -------------------------------- ### SpatialContainer Trait Methods Source: https://docs.rs/space/0.19.0/space/struct.LinearContainer Documentation for methods within the SpatialContainer trait, implemented for LinearContainer. This includes iterating over spatial data, inserting points, and creating instances with specific metrics. ```APIDOC impl SpatialContainer for LinearContainer where M: Metric, PP: ProxyView, VP: ProxyView, { type SpatialIter<'a> = Map, fn(&'a (P, V)) -> (View<'a, PP>, View<'a, VP>)>; fn with_metric(metric: Self::Metric) -> Self; fn insert(&mut self, point: P, value: V); fn iter(&self) -> Self::SpatialIter<'_>; } ``` -------------------------------- ### Rust Space Crate - Knn Trait Source: https://docs.rs/space/0.19.0/space/fn.linear_nn Documentation for the `Knn` trait in the Rust 'space' crate. This trait provides a generic interface for k-nearest neighbors search operations on spatial data. ```rust pub trait Knn where T: Data, Q: ?Sized, M: Metric, { fn knn(&self, query: &Q, k: usize, metric: &M) -> Vec<(usize, T::Distance)>; } ``` -------------------------------- ### LinearContainer Knn Implementation (Rust) Source: https://docs.rs/space/0.19.0/src/space/linear.rs Implements the Knn trait for LinearContainer, enabling k-nearest neighbors and nearest neighbor searches. It utilizes helper functions `linear_knn` and `linear_nn` for the actual search logic, taking the metric, data iterator, query point, and number of neighbors as input. ```rust impl Knn for LinearContainer where M: Metric, PP: ProxyView, VP: ProxyView, { type KnnIter<'a> = vec::IntoIter<(M::Unit, View<'a, PP>, View<'a, VP>)>; fn knn<'a, 'b>(&'a self, query: View<'b, Self::PointProxy>, num: usize) -> Self::KnnIter<'a> { linear_knn::( self.metric, self.data .iter() .map(|(pt, val)| (PP::view(pt), VP::view(val))), query, num, ) .into_iter() } fn nn<'a, 'b>( &'a self, query: View<'b, Self::PointProxy>, ) -> Option<(M::Unit, View<'a, PP>, View<'a, VP>) { linear_nn::( self.metric, self.data ``` -------------------------------- ### Rust Space Crate - ExactSpace Trait Source: https://docs.rs/space/0.19.0/space/fn.linear_nn Documentation for the `ExactSpace` trait in the Rust 'space' crate. This trait defines the interface for spatial data structures that support exact nearest neighbor searches. ```rust pub trait ExactSpace: SpatialContainer where T: Data, Q: ?Sized, M: Metric, { fn exact_nn(&self, query: &Q, k: usize, metric: &M) -> Vec<(usize, T::Distance)>; } ``` -------------------------------- ### From Trait Methods Source: https://docs.rs/space/0.19.0/space/struct.LinearSearch Documentation for the `From` trait, used for creating a new value from another type. The `from` method is the core function for this conversion. ```rust impl From for T fn from(t: T) -> T ``` -------------------------------- ### ExactSpace Trait Documentation Source: https://docs.rs/space/0.19.0/space/trait.ExactSpace Documentation for the ExactSpace trait in the 'space' crate. This trait likely defines methods for exact spatial queries and operations. It is implemented by various spatial data structures. ```APIDOC ExactSpace: A library providing abstractions for spatial datastructures and search Implementors: - [ExactSpace](https://docs.rs/space/0.19.0/space/trait.ExactSpace.html#implementors) In crate space: Traits: - [ExactSpace](https://docs.rs/space/0.19.0/space/trait.ExactSpace.html) ``` -------------------------------- ### NSphere Range Query (Exact) Source: https://docs.rs/space/0.19.0/src/space/lib.rs Performs an exact n-sphere range query to find all neighbors within a specified radius. The results are sorted by distance, with the closest neighbor first. This method relies on the `ExactSpace` trait. ```rust pub trait NSphereRangeQuery: ApproximateSpace { type NSphereIter<'a>: Iterator, View<'a, Self::PointProxy>, View<'a, Self::ValueProxy>, )>; fn nsphere_query<'a, 'b>( &'a self, query: View<'b, Self::PointProxy>, radius: MetricUnit, ) -> Self::NSphereIter<'a>; } ``` -------------------------------- ### Space Trait Documentation Source: https://docs.rs/space/0.19.0/src/space/lib.rs Documentation for the `Space` trait in the 'space' crate. This trait is implemented for metrics that form a metric space and is used for keys in nearest neighbor searches. It outlines the requirements for implementing the trait, including satisfying the triangle inequality and handling zero distances for identical points. Recommendations are provided for using unsigned integers or wrapped floats (like `NoisyFloat`) as metric types. ```rust /// This trait is implemented for metrics that form a metric space. /// It is primarily used for keys in nearest neighbor searches. /// When implementing this trait, it is recommended to choose the smallest unsigned integer that /// represents your metric space, but you may also use a float so long as you wrap it in /// a newtype that enforces the `Ord + Zero + Copy` trait bounds. /// It is recommended to use /// [`NoisyFloat`](https://docs.rs/noisy_float/0.2.0/noisy_float/struct.NoisyFloat.html) /// for this purpose, as it implements the trait bound. /// /// It is important that all metrics that implement this trait satisfy /// the [triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality). /// This requirement basically means that the sum of distances that start /// at a point A and end at a point B can never be less than the distance /// from A to B directly. Note that the metric is required to be an unsigned integer, /// as distances can only be positive and must be fully ordered. /// It is also required that two overlapping points (the same point in space) must return /// a distance of [`Zero::zero`]. /// /// Floating point numbers can be converted to integer metrics by being interpreted as integers by design, /// although some special patterns (like NaN) do not fit into this model. To be interpreted as an unsigned /// integer, the float must be positive zero, subnormal, normal, or positive infinity. Any NaN needs /// to be dealt with before converting into a metric, as they do NOT satisfy the triangle inequality, /// and will lead to errors. You may want to check for positive infinity as well depending on your use case. /// You must remove NaNs if you convert to integers, but you must also remove NaNs if you use an ordered /// wrapper like [`NoisyFloat`](https://docs.rs/noisy_float/0.2.0/noisy_float/struct.NoisyFloat.html). ``` -------------------------------- ### LinearSearch Struct Source: https://docs.rs/space/0.19.0/space/index The LinearSearch struct performs a linear k-nearest neighbors (kNN) search. It iterates through the dataset, maintaining a set of neighbors and using binary search to refine the results. ```Rust struct LinearSearch { // Implementation details for linear kNN search } ``` -------------------------------- ### Space Crate Documentation Coverage Source: https://docs.rs/space/0.19.0/src/space/linear.rs Indicates the percentage of the 'space' crate that is documented. ```rust /// 54.29% of the crate is documented ``` -------------------------------- ### Spatial Search Functions Source: https://docs.rs/space/0.19.0/space/index Functions for performing linear nearest neighbor searches. ```APIDOC linear_knn: This function performs exact linear nearest neighbor search. linear_nn: This function performs exact linear nearest neighbor search. ```