diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-07-08 11:27:18 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-07-08 11:27:18 -0400 |
commit | aa9c2362a081583db2880938edf3aa8379c4f926 (patch) | |
tree | 5a654ad3999435302beea0fa1dce57f58c2d8ed7 | |
parent | 5f85a59d4be37d350bcf1ee62c25ac1f84d71770 (diff) | |
download | acap-aa9c2362a081583db2880938edf3aa8379c4f926.tar.xz |
docs: Add some examples to the main page
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -79,6 +79,33 @@ //! marker trait. For example, a [`VpTree`] will be exact when the [`Proximity`] function is a //! [`Metric`]. //! +//! # Examples +//! +//! ## Searching without owning +//! +//! Since [`Proximity`] has a blanket implementation for references, you can store references in a +//! nearest neighbor index instead of having it hold the data itself: +//! +//! use acap::euclid::Euclidean; +//! use acap::vp::VpTree; +//! use acap::NearestNeighbors; +//! +//! let points = vec![ +//! Euclidean([3, 4]), +//! Euclidean([5, 12]), +//! Euclidean([8, 15]), +//! Euclidean([7, 24]), +//! ]; +//! +//! let tree = VpTree::balanced(points.iter()); +//! +//! let nearest = tree.nearest(&&[7, 7]).unwrap(); +//! assert!(std::ptr::eq(*nearest.item, &points[0])); +//! +//! ## Custom distance functions +//! +//! See the [`Proximity`] documentation. +//! //! [nearest neighbor search]: https://en.wikipedia.org/wiki/Nearest_neighbor_search //! [`distance()`]: Proximity#tymethod.distance //! [`value()`]: Distance#method.value |