summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-07-08 11:27:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-07-08 11:27:18 -0400
commitaa9c2362a081583db2880938edf3aa8379c4f926 (patch)
tree5a654ad3999435302beea0fa1dce57f58c2d8ed7 /src
parent5f85a59d4be37d350bcf1ee62c25ac1f84d71770 (diff)
downloadacap-aa9c2362a081583db2880938edf3aa8379c4f926.tar.xz
docs: Add some examples to the main page
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs27
1 files changed, 27 insertions, 0 deletions
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