[−][src]Struct patricia_tree::map::PatriciaMap
A map based on a patricia tree.
Methods
impl<V> PatriciaMap<V>
[src]
pub fn new() -> Self
[src]
Makes a new empty PatriciaMap
instance.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert!(map.is_empty()); map.insert("foo", 10); assert_eq!(map.len(), 1); assert_eq!(map.get("foo"), Some(&10)); map.remove("foo"); assert_eq!(map.get("foo"), None);
pub fn clear(&mut self)
[src]
Clears this map, removing all values.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.clear(); assert!(map.is_empty());
pub fn contains_key<K: AsRef<[u8]>>(&self, key: K) -> bool
[src]
Returns true
if this map contains a value for the specified key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert!(map.contains_key("foo")); assert!(!map.contains_key("bar"));
pub fn get<K: AsRef<[u8]>>(&self, key: K) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert_eq!(map.get("foo"), Some(&1)); assert_eq!(map.get("bar"), None);
pub fn get_mut<K: AsRef<[u8]>>(&mut self, key: K) -> Option<&mut V>
[src]
Returns a mutable reference to the value corresponding to the key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.get_mut("foo").map(|v| *v = 2); assert_eq!(map.get("foo"), Some(&2));
pub fn get_longest_common_prefix<'a, K: ?Sized>(
&self,
key: &'a K
) -> Option<(&'a [u8], &V)> where
K: AsRef<[u8]>,
[src]
&self,
key: &'a K
) -> Option<(&'a [u8], &V)> where
K: AsRef<[u8]>,
Finds the longest common prefix of key
and the keys in this map,
and returns a reference to the entry whose key matches the prefix.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.insert("foobar", 2); assert_eq!(map.get_longest_common_prefix("fo"), None); assert_eq!(map.get_longest_common_prefix("foo"), Some(("foo".as_bytes(), &1))); assert_eq!(map.get_longest_common_prefix("fooba"), Some(("foo".as_bytes(), &1))); assert_eq!(map.get_longest_common_prefix("foobar"), Some(("foobar".as_bytes(), &2))); assert_eq!(map.get_longest_common_prefix("foobarbaz"), Some(("foobar".as_bytes(), &2)));
pub fn insert<K: AsRef<[u8]>>(&mut self, key: K, value: V) -> Option<V>
[src]
Inserts a key-value pair into this map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old value is returned.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert_eq!(map.insert("foo", 1), None); assert_eq!(map.get("foo"), Some(&1)); assert_eq!(map.insert("foo", 2), Some(1)); assert_eq!(map.get("foo"), Some(&2));
pub fn remove<K: AsRef<[u8]>>(&mut self, key: K) -> Option<V>
[src]
Removes a key from this map, returning the value at the key if the key was previously in it.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert_eq!(map.remove("foo"), Some(1)); assert_eq!(map.remove("foo"), None);
pub fn split_by_prefix<K: AsRef<[u8]>>(&mut self, prefix: K) -> Self
[src]
Splits the map into two at the given prefix.
The returned map contains all the entries of which keys are prefixed by prefix
.
Examples
use patricia_tree::PatriciaMap; let mut a = PatriciaMap::new(); a.insert("rust", 1); a.insert("ruby", 2); a.insert("bash", 3); a.insert("erlang", 4); a.insert("elixir", 5); let b = a.split_by_prefix("e"); assert_eq!(a.len(), 3); assert_eq!(b.len(), 2); assert_eq!(a.keys().collect::<Vec<_>>(), [b"bash", b"ruby", b"rust"]); assert_eq!(b.keys().collect::<Vec<_>>(), [b"elixir", b"erlang"]);
pub fn len(&self) -> usize
[src]
Returns the number of elements in this map.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.insert("bar", 2); assert_eq!(map.len(), 2);
pub fn is_empty(&self) -> bool
[src]
Returns true
if this map contains no elements.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert!(map.is_empty()); map.insert("foo", 1); assert!(!map.is_empty()); map.clear(); assert!(map.is_empty());
ⓘImportant traits for Iter<'a, V>pub fn iter(&self) -> Iter<V>
[src]
Gets an iterator over the entries of this map, sorted by key.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![(Vec::from("bar"), &2), ("baz".into(), &3), ("foo".into(), &1)], map.iter().collect::<Vec<_>>());
ⓘImportant traits for IterMut<'a, V>pub fn iter_mut(&mut self) -> IterMut<V>
[src]
Gets a mutable iterator over the entries of this map, soretd by key.
Examples
use patricia_tree::PatriciaMap; let mut map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); for (_, v) in map.iter_mut() { *v += 10; } assert_eq!(map.get("bar"), Some(&12));
pub fn iter_prefix<'a, 'b>(
&'a self,
prefix: &'b [u8]
) -> impl 'a + Iterator<Item = (Vec<u8>, &'a V)> where
'b: 'a,
[src]
&'a self,
prefix: &'b [u8]
) -> impl 'a + Iterator<Item = (Vec<u8>, &'a V)> where
'b: 'a,
Gets an iterator over the entries having the given prefix of this map, sorted by key.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![(Vec::from("bar"), &2), ("baz".into(), &3)], map.iter_prefix(b"ba").collect::<Vec<_>>());
ⓘImportant traits for Keys<'a, V>pub fn keys(&self) -> Keys<V>
[src]
Gets an iterator over the keys of this map, in sorted order.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![Vec::from("bar"), "baz".into(), "foo".into()], map.keys().collect::<Vec<_>>());
ⓘImportant traits for Values<'a, V>pub fn values(&self) -> Values<V>
[src]
Gets an iterator over the values of this map, in order by key.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![2, 3, 1], map.values().cloned().collect::<Vec<_>>());
ⓘImportant traits for ValuesMut<'a, V>pub fn values_mut(&mut self) -> ValuesMut<V>
[src]
Gets a mutable iterator over the values of this map, in order by key.
Examples
use patricia_tree::PatriciaMap; let mut map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); for v in map.values_mut() { *v += 10; } assert_eq!(vec![12, 13, 11], map.values().cloned().collect::<Vec<_>>());
Trait Implementations
impl<V> AsRef<Node<V>> for PatriciaMap<V>
[src]
impl<V> From<Node<V>> for PatriciaMap<V>
[src]
impl<V> From<PatriciaMap<V>> for Node<V>
[src]
fn from(f: PatriciaMap<V>) -> Self
[src]
impl<K, V> Extend<(K, V)> for PatriciaMap<V> where
K: AsRef<[u8]>,
[src]
K: AsRef<[u8]>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
impl<V> IntoIterator for PatriciaMap<V>
[src]
type Item = (Vec<u8>, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<V: Clone> Clone for PatriciaMap<V>
[src]
fn clone(&self) -> PatriciaMap<V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<V> Default for PatriciaMap<V>
[src]
impl<V: Debug> Debug for PatriciaMap<V>
[src]
impl<K, V> FromIterator<(K, V)> for PatriciaMap<V> where
K: AsRef<[u8]>,
[src]
K: AsRef<[u8]>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
Auto Trait Implementations
impl<V> Send for PatriciaMap<V>
impl<V> !Sync for PatriciaMap<V>
impl<V> Unpin for PatriciaMap<V> where
V: Unpin,
V: Unpin,
impl<V> UnwindSafe for PatriciaMap<V> where
V: UnwindSafe,
V: UnwindSafe,
impl<V> RefUnwindSafe for PatriciaMap<V> where
V: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,