Add HnswMap::iter() method
This commit is contained in:
parent
4b43a11e26
commit
6fda656afb
|
@ -155,14 +155,26 @@ where
|
||||||
&'a self,
|
&'a self,
|
||||||
point: &P,
|
point: &P,
|
||||||
search: &'a mut Search,
|
search: &'a mut Search,
|
||||||
) -> impl Iterator<Item = (f32, &'a P, &'a V)> + ExactSizeIterator + 'a {
|
) -> impl Iterator<Item = MapItem<'a, P, V>> + ExactSizeIterator + 'a {
|
||||||
self.hnsw
|
self.hnsw.search(point, search).map(move |item| MapItem {
|
||||||
.search(point, search)
|
distance: item.distance,
|
||||||
.map(move |(distance, pid, point)| {
|
pid: item.pid,
|
||||||
let value = &self.values[pid.0 as usize];
|
point: item.point,
|
||||||
(distance, point, value)
|
value: &self.values[item.pid.0 as usize],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterate over the keys and values in this index
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = (PointId, &P)> {
|
||||||
|
self.hnsw.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MapItem<'a, P, V> {
|
||||||
|
pub distance: f32,
|
||||||
|
pub pid: PointId,
|
||||||
|
pub point: &'a P,
|
||||||
|
pub value: &'a V,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
|
|
Loading…
Reference in New Issue