Struct heapless::LinearMap [−][src]
A fixed capacity map / dictionary that performs lookups via linear search
Note that as this map doesn’t use hashing so most operations are O(N) instead of O(1)
Implementations
impl<K, V, N> LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
pub fn new() -> Self
[src]
Creates an empty LinearMap
Examples
use heapless::LinearMap; use heapless::consts::*; // allocate the map on the stack let mut map: LinearMap<&str, isize, U8> = LinearMap::new(); // allocate the map in a static variable static mut MAP: LinearMap<&str, isize, U8> = LinearMap(heapless::i::LinearMap::new());
pub fn capacity(&self) -> usize
[src]
Returns the number of elements that the map can hold
Computes in O(1) time
Examples
use heapless::LinearMap; use heapless::consts::*; let map: LinearMap<&str, isize, U8> = LinearMap::new(); assert_eq!(map.capacity(), 8);
pub fn clear(&mut self)
[src]
Clears the map, removing all key-value pairs
Computes in O(1) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert(1, "a").unwrap(); map.clear(); assert!(map.is_empty());
pub fn contains_key(&self, key: &K) -> bool
[src]
Returns true if the map contains a value for the specified key.
Computes in O(N) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert(1, "a").unwrap(); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Eq,
[src]
K: Borrow<Q>,
Q: Eq,
Returns a reference to the value corresponding to the key
Computes in O(N) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert(1, "a").unwrap(); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None);
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Eq,
[src]
K: Borrow<Q>,
Q: Eq,
Returns a mutable reference to the value corresponding to the key
Computes in O(N) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert(1, "a").unwrap(); if let Some(x) = map.get_mut(&1) { *x = "b"; } assert_eq!(map[&1], "b");
pub fn len(&self) -> usize
[src]
Returns the number of elements in this map
Computes in O(1) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut a: LinearMap<_, _, U8> = LinearMap::new(); assert_eq!(a.len(), 0); a.insert(1, "a").unwrap(); assert_eq!(a.len(), 1);
pub fn insert(&mut self, key: K, value: V) -> Result<Option<V>, (K, V)>
[src]
Inserts a key-value pair into the 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.
Computes in O(N) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); assert_eq!(map.insert(37, "a").unwrap(), None); assert_eq!(map.is_empty(), false); map.insert(37, "b").unwrap(); assert_eq!(map.insert(37, "c").unwrap(), Some("b")); assert_eq!(map[&37], "c");
pub fn is_empty(&self) -> bool
[src]
Returns true if the map contains no elements
Computes in O(1) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut a: LinearMap<_, _, U8> = LinearMap::new(); assert!(a.is_empty()); a.insert(1, "a").unwrap(); assert!(!a.is_empty());
pub fn iter(&self) -> Iter<'_, K, V>
[src]
An iterator visiting all key-value pairs in arbitrary order.
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert("a", 1).unwrap(); map.insert("b", 2).unwrap(); map.insert("c", 3).unwrap(); for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
[src]
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert("a", 1).unwrap(); map.insert("b", 2).unwrap(); map.insert("c", 3).unwrap(); // Update all values for (_, val) in map.iter_mut() { *val = 2; } for (key, val) in &map { println!("key: {} val: {}", key, val); }
pub fn keys(&self) -> impl Iterator<Item = &K>
[src]
An iterator visiting all keys in arbitrary order
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert("a", 1).unwrap(); map.insert("b", 2).unwrap(); map.insert("c", 3).unwrap(); for key in map.keys() { println!("{}", key); }
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Eq,
[src]
K: Borrow<Q>,
Q: Eq,
Removes a key from the map, returning the value at the key if the key was previously in the map
Computes in O(N) time
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert(1, "a").unwrap(); assert_eq!(map.remove(&1), Some("a")); assert_eq!(map.remove(&1), None);
pub fn values(&self) -> impl Iterator<Item = &V>
[src]
An iterator visiting all values in arbitrary order
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert("a", 1).unwrap(); map.insert("b", 2).unwrap(); map.insert("c", 3).unwrap(); for val in map.values() { println!("{}", val); }
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
[src]
An iterator visiting all values mutably in arbitrary order
Examples
use heapless::LinearMap; use heapless::consts::*; let mut map: LinearMap<_, _, U8> = LinearMap::new(); map.insert("a", 1).unwrap(); map.insert("b", 2).unwrap(); map.insert("c", 3).unwrap(); for val in map.values_mut() { *val += 10; } for val in map.values() { println!("{}", val); }
Trait Implementations
impl<K, V, N> Clone for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq + Clone,
V: Clone,
[src]
N: ArrayLength<(K, V)>,
K: Eq + Clone,
V: Clone,
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K, V, N> Debug for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq + Debug,
V: Debug,
[src]
N: ArrayLength<(K, V)>,
K: Eq + Debug,
V: Debug,
impl<K, V, N> Default for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
impl<K, V, N> Drop for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
impl<K, V, N> Eq for LinearMap<K, V, N> where
K: Eq,
V: PartialEq,
N: ArrayLength<(K, V)>,
[src]
K: Eq,
V: PartialEq,
N: ArrayLength<(K, V)>,
impl<K, V, N> FromIterator<(K, V)> for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
impl<'a, K, V, N, Q: ?Sized> Index<&'a Q> for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Borrow<Q> + Eq,
Q: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Borrow<Q> + Eq,
Q: Eq,
impl<'a, K, V, N, Q: ?Sized> IndexMut<&'a Q> for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Borrow<Q> + Eq,
Q: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Borrow<Q> + Eq,
Q: Eq,
impl<K, V, N> IntoIterator for LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<K, V, N>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K, V, N> IntoIterator for &'a LinearMap<K, V, N> where
N: ArrayLength<(K, V)>,
K: Eq,
[src]
N: ArrayLength<(K, V)>,
K: Eq,
type Item = (&'a 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, V, N, N2> PartialEq<LinearMap<K, V, N2>> for LinearMap<K, V, N> where
K: Eq,
V: PartialEq,
N: ArrayLength<(K, V)>,
N2: ArrayLength<(K, V)>,
[src]
K: Eq,
V: PartialEq,
N: ArrayLength<(K, V)>,
N2: ArrayLength<(K, V)>,
Auto Trait Implementations
impl<K, V, N> RefUnwindSafe for LinearMap<K, V, N> where
<N as ArrayLength<(K, V)>>::ArrayType: RefUnwindSafe,
<N as ArrayLength<(K, V)>>::ArrayType: RefUnwindSafe,
impl<K, V, N> Send for LinearMap<K, V, N> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V, N> Sync for LinearMap<K, V, N> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V, N> Unpin for LinearMap<K, V, N> where
<N as ArrayLength<(K, V)>>::ArrayType: Unpin,
<N as ArrayLength<(K, V)>>::ArrayType: Unpin,
impl<K, V, N> UnwindSafe for LinearMap<K, V, N> where
<N as ArrayLength<(K, V)>>::ArrayType: UnwindSafe,
<N as ArrayLength<(K, V)>>::ArrayType: 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,
pub 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> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,