Struct BKTreeMap

Source
pub struct BKTreeMap<K, M, V> { /* private fields */ }
Expand description

a tree for quickly finding items separated by a small discrete distance

Implementations§

Source§

impl<K, M, V> BKTreeMap<K, M, V>

Source

pub fn append<M2>(&mut self, other: &mut BKTreeMap<K, M2, V>)
where M: DiscreteMetric<K, K>,

moves all elements from other into self, leaving other empty. If a key from other is already present in self, the respective value from self will be overwritten with the respective value from other

Source

pub fn clear(&mut self)

clears the map, removing all elements

Source

pub fn close_iter<Q>( &self, key: Q, maxdistance: usize, ) -> CloseMapIter<'_, K, M, Q, V>
where M: DiscreteMetric<K, Q>,

gets the key value pairs whose distance is at most max distance from key

Source

pub fn close_keys<Q>( &self, key: Q, maxdistance: usize, ) -> CloseKeyIter<'_, K, M, Q, V>
where M: DiscreteMetric<K, Q>,

gets the keys whose distance is at most max distance from key

Source

pub fn close_values<Q>( &self, key: Q, maxdistance: usize, ) -> CloseValIter<'_, K, M, Q, V>
where M: DiscreteMetric<K, Q>,

gets the values whose keys are at most max distance from key

Source

pub fn close_sorted<'a, Q: ?Sized>( &self, key: &Q, maxdistance: usize, ) -> Vec<(&K, &V, usize)>
where M: DiscreteMetric<K, Q>,

returns the key value pairs at most maxdistance from the key, sorted by distance

Source

pub fn close_sorted_mut<'a, Q: ?Sized>( &mut self, key: &Q, maxdistance: usize, ) -> Vec<(&K, &mut V, usize)>
where M: DiscreteMetric<K, Q>,

returns the key value pairs at most maxdistance from the key, sorted by distance

Source

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

tests if a key at most maxdistance from the given key is in the map

Source

pub fn get<Q: ?Sized>(&self, key: &Q, maxdistance: usize) -> Option<(&V, usize)>
where M: DiscreteMetric<K, Q>,

gets the value whose key is closest to the given key, or None if the map contains no key at most max distance from the given key. If there are multiple closest keys, exactly which is returned is unspecified

Examples found in repository?
examples/string_matching.rs (line 10)
1pub fn main(){
2	let mut tree=BKTreeMap::new(Levenshtein::new());
3	tree.insert("calculate","mathematics");
4	tree.insert("cat","pet");
5	tree.insert("kat","name");
6	tree.insert("hello","greeting");
7	tree.insert("hi","greeting");
8	tree.insert("linear","mathematics");
9
10	println!("{}",tree.get("calculator",2).map(|(s,_d)|*s).unwrap_or("not found"));
11	println!("{}",tree.get("hey",2).map(|(s,_d)|*s).unwrap_or("not found"));
12	println!("{}",tree.get("kate",2).map(|(s,_d)|*s).unwrap_or("not found"));
13	println!("{}",tree.get("line",2).map(|(s,_d)|*s).unwrap_or("not found"));
14	println!("{}",tree.get("serotonin",2).map(|(s,_d)|*s).unwrap_or("not found"));
15}
Source

pub fn get_key_value<Q: ?Sized>( &self, key: &Q, maxdistance: usize, ) -> Option<(&K, &V, usize)>
where M: DiscreteMetric<K, Q>,

gets the key value pair and distance whose key is closest to the given key, or None if the map contains no key at most max distance from the given key. If there are multiple closest keys, exactly which is returned is unspecified

Source

pub fn get_mut<Q: ?Sized>( &mut self, key: &Q, maxdistance: usize, ) -> Option<(&mut V, usize)>
where M: DiscreteMetric<K, Q>,

gets the value whose key is closest to the given key, or None if the map contains no key at most max distance from the given key. If there are multiple closest keys, exactly which is returned is unspecified

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>
where M: DiscreteMetric<K, K>,

inserts a key-value pair into the map, returning the previous value at that key, or None if there was no previous value. Keys are considered equal if the the distance between them is 0. If the old value is returned the key is not updated.

Examples found in repository?
examples/string_matching.rs (line 3)
1pub fn main(){
2	let mut tree=BKTreeMap::new(Levenshtein::new());
3	tree.insert("calculate","mathematics");
4	tree.insert("cat","pet");
5	tree.insert("kat","name");
6	tree.insert("hello","greeting");
7	tree.insert("hi","greeting");
8	tree.insert("linear","mathematics");
9
10	println!("{}",tree.get("calculator",2).map(|(s,_d)|*s).unwrap_or("not found"));
11	println!("{}",tree.get("hey",2).map(|(s,_d)|*s).unwrap_or("not found"));
12	println!("{}",tree.get("kate",2).map(|(s,_d)|*s).unwrap_or("not found"));
13	println!("{}",tree.get("line",2).map(|(s,_d)|*s).unwrap_or("not found"));
14	println!("{}",tree.get("serotonin",2).map(|(s,_d)|*s).unwrap_or("not found"));
15}
Source

pub fn into_keys(self) -> IntoKeysIter<K, V>

makes an iterator over the keys

Source

pub fn into_values(self) -> IntoValsIter<K, V>

makes an iterator over the values

Source

pub fn is_empty(&self) -> bool

returns true if the map contains no entries

Source

pub fn iter(&self) -> MapIter<'_, K, V>

makes an iterator over the mappings

Source

pub fn iter_mut(&mut self) -> MapIterMut<'_, K, V>

makes an iterator over the mappings

Source

pub fn keys(&self) -> KeyIter<'_, K, V>

makes an iterator over the keys

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 len(&self) -> usize

returns the number of entries in the map

Source

pub fn new(metric: M) -> Self

creates a new tree

Examples found in repository?
examples/string_matching.rs (line 2)
1pub fn main(){
2	let mut tree=BKTreeMap::new(Levenshtein::new());
3	tree.insert("calculate","mathematics");
4	tree.insert("cat","pet");
5	tree.insert("kat","name");
6	tree.insert("hello","greeting");
7	tree.insert("hi","greeting");
8	tree.insert("linear","mathematics");
9
10	println!("{}",tree.get("calculator",2).map(|(s,_d)|*s).unwrap_or("not found"));
11	println!("{}",tree.get("hey",2).map(|(s,_d)|*s).unwrap_or("not found"));
12	println!("{}",tree.get("kate",2).map(|(s,_d)|*s).unwrap_or("not found"));
13	println!("{}",tree.get("line",2).map(|(s,_d)|*s).unwrap_or("not found"));
14	println!("{}",tree.get("serotonin",2).map(|(s,_d)|*s).unwrap_or("not found"));
15}
Source

pub fn remove<Q: ?Sized>( &mut self, key: &Q, maxdistance: usize, ) -> Option<(V, usize)>
where M: DiscreteMetric<K, K> + DiscreteMetric<K, Q>,

removes the closest mapping whose key at most maxdistance from the given key. If there are multiple closest keys, exactly which is removed is unspecified. This particular tree type doesn’t allow super efficient removal, so try to avoid using too much.

Source

pub fn remove_entry<Q: ?Sized>( &mut self, key: &Q, maxdistance: usize, ) -> Option<(K, V, usize)>
where M: DiscreteMetric<K, K> + DiscreteMetric<K, Q>,

removes the closest mapping whose key at most maxdistance from the given key. If there are multiple closest keys, exactly which is removed is unspecified. This particular tree type doesn’t allow super efficient removal, so try to avoid using too much.

Source

pub fn retain<F: FnMut(&K, &mut V) -> bool>(&mut self, f: F)
where M: DiscreteMetric<K, K>,

removes all the mappings for which f returns false

Source

pub fn values(&self) -> ValIter<'_, K, V>

makes an iterator over the values

Source

pub fn values_mut(&mut self) -> ValIterMut<'_, K, V>

makes an iterator over the values

Trait Implementations§

Source§

impl<K, M, V> AsMut<BKTreeMap<K, M, V>> for BKTreeMap<K, M, V>

Source§

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

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

impl<K, M, V> AsRef<BKTreeMap<K, M, V>> for BKTreeMap<K, M, V>

Source§

fn as_ref(&self) -> &Self

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

impl<K: Clone, M: Clone, V: Clone> Clone for BKTreeMap<K, M, V>

Source§

fn clone(&self) -> BKTreeMap<K, M, V>

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<K: Debug, M: Debug, V: Debug> Debug for BKTreeMap<K, M, V>

Source§

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

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

impl<K, M: Default, V> Default for BKTreeMap<K, M, V>

Source§

fn default() -> Self

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

impl<K, M: DiscreteMetric<K, K>, V> Extend<(K, V)> for BKTreeMap<K, M, V>

Source§

fn extend<I: IntoIterator<Item = (K, V)>>(&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<K, M: Default + DiscreteMetric<K, K>, V> FromIterator<(K, V)> for BKTreeMap<K, M, V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K, M: DiscreteMetric<K, Q>, Q, V> Index<&Q> for BKTreeMap<K, M, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<K, M: DiscreteMetric<K, Q>, Q, V> IndexMut<&Q> for BKTreeMap<K, M, V>

Source§

fn index_mut(&mut self, index: &Q) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, K, M, V> IntoIterator for &'a BKTreeMap<K, M, V>

Source§

type IntoIter = MapIter<'a, K, V>

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

type Item = (&'a K, &'a V)

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<'a, K, M, V> IntoIterator for &'a mut BKTreeMap<K, M, V>

Source§

type IntoIter = MapIterMut<'a, K, V>

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

type Item = (&'a K, &'a mut V)

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<K, M, V> IntoIterator for BKTreeMap<K, M, V>

Source§

type IntoIter = MapIntoIter<K, V>

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

type Item = (K, V)

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<K, M, V> Freeze for BKTreeMap<K, M, V>
where M: Freeze, K: Freeze, V: Freeze,

§

impl<K, M, V> RefUnwindSafe for BKTreeMap<K, M, V>

§

impl<K, M, V> Send for BKTreeMap<K, M, V>
where M: Send, K: Send, V: Send,

§

impl<K, M, V> Sync for BKTreeMap<K, M, V>
where M: Sync, K: Sync, V: Sync,

§

impl<K, M, V> Unpin for BKTreeMap<K, M, V>
where M: Unpin, K: Unpin, V: Unpin,

§

impl<K, M, V> UnwindSafe for BKTreeMap<K, M, V>

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.