Skip to content

Commit aa9c236

Browse files
committed
docs: Add some examples to the main page
1 parent 5f85a59 commit aa9c236

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@
7979
//! marker trait. For example, a [`VpTree`] will be exact when the [`Proximity`] function is a
8080
//! [`Metric`].
8181
//!
82+
//! # Examples
83+
//!
84+
//! ## Searching without owning
85+
//!
86+
//! Since [`Proximity`] has a blanket implementation for references, you can store references in a
87+
//! nearest neighbor index instead of having it hold the data itself:
88+
//!
89+
//! use acap::euclid::Euclidean;
90+
//! use acap::vp::VpTree;
91+
//! use acap::NearestNeighbors;
92+
//!
93+
//! let points = vec![
94+
//! Euclidean([3, 4]),
95+
//! Euclidean([5, 12]),
96+
//! Euclidean([8, 15]),
97+
//! Euclidean([7, 24]),
98+
//! ];
99+
//!
100+
//! let tree = VpTree::balanced(points.iter());
101+
//!
102+
//! let nearest = tree.nearest(&&[7, 7]).unwrap();
103+
//! assert!(std::ptr::eq(*nearest.item, &points[0]));
104+
//!
105+
//! ## Custom distance functions
106+
//!
107+
//! See the [`Proximity`] documentation.
108+
//!
82109
//! [nearest neighbor search]: https://en.wikipedia.org/wiki/Nearest_neighbor_search
83110
//! [`distance()`]: Proximity#tymethod.distance
84111
//! [`value()`]: Distance#method.value

0 commit comments

Comments
 (0)