summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/exhaustive.rs40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/exhaustive.rs b/src/exhaustive.rs
index 320994e..442850c 100644
--- a/src/exhaustive.rs
+++ b/src/exhaustive.rs
@@ -15,9 +15,9 @@ impl<T> ExhaustiveSearch<T> {
Self(Vec::new())
}
- /// Add a new item to the index.
- pub fn push(&mut self, item: T) {
- self.0.push(item);
+ /// Iterate over the items stored in this index.
+ pub fn iter(&self) -> Iter<T> {
+ (&self).into_iter()
}
/// Get the size of this index.
@@ -29,6 +29,11 @@ impl<T> ExhaustiveSearch<T> {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
+
+ /// Add a new item to the index.
+ pub fn push(&mut self, item: T) {
+ self.0.push(item);
+ }
}
impl<T> Default for ExhaustiveSearch<T> {
@@ -64,6 +69,35 @@ impl<T> IntoIterator for ExhaustiveSearch<T> {
}
}
+/// An iterator over the values in an exhaustive index.
+#[derive(Debug)]
+pub struct Iter<'a, T>(std::slice::Iter<'a, T>);
+
+impl<'a, T> Iterator for Iter<'a, T> {
+ type Item = &'a T;
+
+ fn next(&mut self) -> Option<&'a T> {
+ self.0.next()
+ }
+}
+
+impl<'a, T> IntoIterator for &'a ExhaustiveSearch<T> {
+ type Item = &'a T;
+ type IntoIter = Iter<'a, T>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ Iter(self.0.iter())
+ }
+}
+
+impl<T> Extend<T> for ExhaustiveSearch<T> {
+ fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
+ for value in iter {
+ self.push(value);
+ }
+ }
+}
+
impl<K: Proximity<V>, V> NearestNeighbors<K, V> for ExhaustiveSearch<V> {
fn search<'k, 'v, N>(&'v self, mut neighborhood: N) -> N
where