[−][src]Struct prefix_tree::PrefixMap
A map implemented with prefix tree.
Methods
impl<K: Eq + Clone, V> PrefixMap<K, V>
[src]
pub fn new() -> PrefixMap<K, V>
[src]
Creates an empty PrefixMap
.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new();
pub fn contains_key<Q>(&self, key: Q) -> bool where
Q: AsRef<[K]>,
[src]
Q: AsRef<[K]>,
Returns true
if the map contains a value for the specified key.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); map.insert("foo", 1); assert_eq!(map.contains_key("foo"), true); assert_eq!(map.contains_key("bar"), false);
pub fn clear(&mut self)
[src]
Clears the map, removing all key-value pairs.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); map.insert("foo", 1); map.clear(); assert!(map.is_empty());
pub fn get<Q>(&self, key: Q) -> Option<&V> where
Q: AsRef<[K]>,
[src]
Q: AsRef<[K]>,
Returns a reference to the value corresponding to the key.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); map.insert("foo", 1); assert_eq!(map.get("foo"), Some(&1)); assert_eq!(map.get("bar"), None);
pub fn get_mut<Q>(&mut self, key: Q) -> Option<&mut V> where
Q: AsRef<[K]>,
[src]
Q: AsRef<[K]>,
Returns a mutable reference to the value corresponding to the key.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); map.insert("foo", 1); if let Some(x) = map.get_mut("foo") { *x = 2; } assert_eq!(map.get("foo"), Some(&2));
pub fn insert<Q>(&mut self, key: Q, value: V) -> Option<V> where
Q: AsRef<[K]>,
[src]
Q: AsRef<[K]>,
Inserts a key-value pair into the map.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); assert_eq!(map.insert("a", 42), None); assert_eq!(map.is_empty(), false); assert_eq!(map.insert("a", 5), Some(42)); assert_eq!(map.get("a"), Some(&5));
pub fn remove<Q>(&mut self, key: Q) -> Option<V> where
Q: AsRef<[K]>,
[src]
Q: AsRef<[K]>,
Removes a key from the map, returning the value at the key if the key was previously in the map.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); assert_eq!(map.insert("a", 42), None); assert_eq!(map.remove("a"), Some(42)); assert_eq!(map.get("a"), None);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the map contains no elements.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); assert_eq!(map.is_empty(), true); map.insert("foo", 1); assert_eq!(map.is_empty(), false);
pub fn len(&self) -> usize
[src]
Returns the number of elements in the map.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); assert_eq!(map.len(), 0); map.insert("foo", 1); assert_eq!(map.len(), 1);
pub fn iter(&self) -> Iter<K, V>
[src]
Gets an iterator over the entries of the map, in arbitrary order.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<u8, i32> = PrefixMap::new(); map.insert("1", 9); map.insert("2", 8); map.insert("3", 7); for (key, value) in map.iter() { println!("{:?}: {:?}", key, value); }
pub fn keys(&self) -> Keys<K, V>
[src]
Gets an iterator over the keys of the map, in arbitrary order.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<i32, i32> = PrefixMap::new(); map.insert([1], 2); map.insert([2], 3); assert_eq!(map.keys().collect::<Vec<_>>(), vec![vec![1], vec![2]]);
pub fn values(&self) -> Values<K, V>
[src]
Gets an iterator over the values of the map, in arbitrary order.
Examples
use prefix_tree::PrefixMap; let mut map: PrefixMap<i32, i32> = PrefixMap::new(); map.insert([1], 2); map.insert([2], 3); assert_eq!(map.values().cloned().collect::<Vec<_>>(), vec![2, 3]);
Trait Implementations
impl<K: Clone, V: Clone> Clone for PrefixMap<K, V>
[src]
impl<K: Debug, V: Debug> Debug for PrefixMap<K, V>
[src]
impl<K: Default, V: Default> Default for PrefixMap<K, V>
[src]
impl<K: Eq + Clone, V: Eq> Eq for PrefixMap<K, V>
[src]
impl<'a, K: 'a + Eq + Clone, V: 'a> FromIterator<(&'a [K], V)> for PrefixMap<K, V>
[src]
impl<K: Eq + Clone + Hash, V: Hash> Hash for PrefixMap<K, V>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<K: Eq + Clone, V, Q: AsRef<[K]>> Index<Q> for PrefixMap<K, V>
[src]
impl<'a, K: 'a + Eq + Clone, V: 'a> IntoIterator for &'a PrefixMap<K, V>
[src]
type Item = (Vec<K>, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<K: Eq + Clone, V: Eq> PartialEq<PrefixMap<K, V>> for PrefixMap<K, V>
[src]
Auto Trait Implementations
impl<K, V> RefUnwindSafe for PrefixMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for PrefixMap<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for PrefixMap<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Unpin for PrefixMap<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for PrefixMap<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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 = Infallible
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>,