From aa9c2362a081583db2880938edf3aa8379c4f926 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 8 Jul 2020 11:27:18 -0400 Subject: docs: Add some examples to the main page --- src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 57f3dac..28ebdd1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 -- cgit v1.2.3