Struct BKTreeSet

Source
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>

Source

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

Source

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?
examples/pair_close_points.rs (line 6)
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}
Source

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

Source

pub fn contains<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> bool
where M: DiscreteMetric<E, Q>,

tests if the set contains an element within max distance of the key

Source

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

Source

pub fn insert(&mut self, value: E) -> bool
where M: DiscreteMetric<E, E>,

inserts

Source

pub fn is_empty(&self) -> bool

returns true if the set contains no elements

Source

pub fn iter(&self) -> SetIter<'_, E>

makes an iterator over the items

Source

pub fn len(&self) -> usize

returns the number of elements in the set

Source

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

Source

pub fn new(metric: M) -> Self

creates a new tree

Source

pub fn remove<Q: ?Sized>(&mut self, key: &Q, maxdistance: usize) -> bool
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.

Source

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

Source

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> AsMut<BKTreeSet<E, M>> for BKTreeSet<E, M>

Source§

fn as_mut(&mut self) -> &mut Self

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<E, M> AsRef<BKTreeSet<E, M>> for BKTreeSet<E, M>

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<E: Clone, M: Clone> Clone for BKTreeSet<E, M>

Source§

fn clone(&self) -> BKTreeSet<E, M>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Debug, M: Debug> Debug for BKTreeSet<E, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E, M: Default> Default for BKTreeSet<E, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<E, M: DiscreteMetric<E, E>> Extend<E> for BKTreeSet<E, M>

Source§

fn extend<I: IntoIterator<Item = E>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<E, M: Default + DiscreteMetric<E, E>> FromIterator<E> for BKTreeSet<E, M>

Source§

fn from_iter<I: IntoIterator<Item = E>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, E, M> IntoIterator for &'a BKTreeSet<E, M>

Source§

type IntoIter = SetIter<'a, E>

Which kind of iterator are we turning this into?
Source§

type Item = &'a E

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E, M> IntoIterator for BKTreeSet<E, M>

Source§

type IntoIter = SetIntoIter<E>

Which kind of iterator are we turning this into?
Source§

type Item = E

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<E, M> Freeze for BKTreeSet<E, M>
where M: Freeze, E: Freeze,

§

impl<E, M> RefUnwindSafe for BKTreeSet<E, M>

§

impl<E, M> Send for BKTreeSet<E, M>
where M: Send, E: Send,

§

impl<E, M> Sync for BKTreeSet<E, M>
where M: Sync, E: Sync,

§

impl<E, M> Unpin for BKTreeSet<E, M>
where M: Unpin, E: Unpin,

§

impl<E, M> UnwindSafe for BKTreeSet<E, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.