pub struct BKTreeSet<E, M> { /* private fields */ }
Expand description
a set for quickly finding items separated by a small discrete distance, implemented as a thin wrapper over BKTreeMap
Implementations§
Source§impl<E, M> BKTreeSet<E, M>
impl<E, M> BKTreeSet<E, M>
Sourcepub fn append<M2>(&mut self, other: &mut BKTreeSet<E, M2>)where
M: DiscreteMetric<E, E>,
pub fn append<M2>(&mut self, other: &mut BKTreeSet<E, M2>)where
M: DiscreteMetric<E, E>,
moves all elements from other into self, leaving other empty
Sourcepub fn close_iter<Q>(
&self,
key: Q,
maxdistance: usize,
) -> CloseSetIter<'_, E, M, Q> ⓘwhere
M: DiscreteMetric<E, Q>,
pub fn close_iter<Q>(
&self,
key: Q,
maxdistance: usize,
) -> CloseSetIter<'_, E, M, Q> ⓘwhere
M: DiscreteMetric<E, Q>,
gets the items whose distance is at most max distance from key
Examples found in repository?
1pub fn main(){
2 let vertices=[[-1.5, 2.0],[-1.6, 1.6],[-1.6, 1.1],[ 1.5, 1.3],[ 1.0,-0.1],
3 [ 0.5, 0.3],[-2.0, 1.0],[ 0.5,-1.0],[ 0.9, 0.8],[ 2.0, 2.0]];
4 let tree:BKTreeSet<[f32;2],CeilL2>=vertices.into_iter().collect();
5 let mut edges:Vec<([f32;2],[f32;2])>=vertices.into_iter().flat_map(|u|{
6 let close=tree.close_iter(u,1).map(|(v,_d)|*v).filter(move|&v|u!=v);
7 close.map(move|v|if u<v{(u,v)}else{(v,u)})
8 }).collect();
9 edges.sort_unstable_by_key(|([ux,uy],[vx,vy])|[ux.to_bits(),uy.to_bits(),vx.to_bits(),vy.to_bits()]);
10 edges.dedup();
11
12 edges.iter().for_each(|(p,q)|{
13 println!("([{}, {}], [{}, {}])",p[0],p[1],q[0],q[1]);
14 });
15}
Sourcepub fn close_sorted<'a, Q: ?Sized>(
&self,
key: &Q,
maxdistance: usize,
) -> Vec<(&E, usize)>where
M: DiscreteMetric<E, Q>,
pub fn close_sorted<'a, Q: ?Sized>(
&self,
key: &Q,
maxdistance: usize,
) -> Vec<(&E, usize)>where
M: DiscreteMetric<E, Q>,
returns the elements at most maxdistance from the key, sorted by distance
Sourcepub fn contains<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> boolwhere
M: DiscreteMetric<E, Q>,
pub fn contains<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> boolwhere
M: DiscreteMetric<E, Q>,
tests if the set contains an element within max distance of the key
Sourcepub fn get<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> Option<(&E, usize)>where
M: DiscreteMetric<E, Q>,
pub fn get<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> Option<(&E, usize)>where
M: DiscreteMetric<E, Q>,
returns a reference to the element in the set that is closest to the key within max distance, or None if the set contains no element at most max distance from the given element. If there are multiple closest elements, exactly which is returned is unspecified
Sourcepub fn insert(&mut self, value: E) -> boolwhere
M: DiscreteMetric<E, E>,
pub fn insert(&mut self, value: E) -> boolwhere
M: DiscreteMetric<E, E>,
inserts
Sourcepub fn metric(&self) -> &M
pub fn metric(&self) -> &M
references the metric. avoid modifying the metric in a way that changes the distances because that will most likely cause unspecified incorrect behavior
Sourcepub fn remove<Q: ?Sized>(&mut self, key: &Q, maxdistance: usize) -> boolwhere
M: DiscreteMetric<E, Q> + DiscreteMetric<E, E>,
pub fn remove<Q: ?Sized>(&mut self, key: &Q, maxdistance: usize) -> boolwhere
M: DiscreteMetric<E, Q> + DiscreteMetric<E, E>,
removes an item from the tree. This particular tree type doesn’t allow super efficient removal, so try to avoid using too much.
Sourcepub fn retain<F: FnMut(&E) -> bool>(&mut self, f: F)where
M: DiscreteMetric<E, E>,
pub fn retain<F: FnMut(&E) -> bool>(&mut self, f: F)where
M: DiscreteMetric<E, E>,
removes all the elements for which f returns false
Sourcepub fn take<Q: ?Sized>(
&mut self,
key: &Q,
maxdistance: usize,
) -> Option<(E, usize)>where
M: DiscreteMetric<E, Q> + DiscreteMetric<E, E>,
pub fn take<Q: ?Sized>(
&mut self,
key: &Q,
maxdistance: usize,
) -> Option<(E, usize)>where
M: DiscreteMetric<E, Q> + DiscreteMetric<E, E>,
removes an item from the tree. This particular tree type doesn’t allow super efficient removal, so try to avoid using too much.
Trait Implementations§
Source§impl<E, M: DiscreteMetric<E, E>> Extend<E> for BKTreeSet<E, M>
impl<E, M: DiscreteMetric<E, E>> Extend<E> for BKTreeSet<E, M>
Source§fn extend<I: IntoIterator<Item = E>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = E>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)