Added is_full to LinearMap

This commit is contained in:
Oliver Rockstedt 2024-10-07 12:17:31 +02:00
parent f6b94876b9
commit c603323c23
2 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `is_full` to `BinaryHeap`
- Added `is_full` to `IndexMap`
- Added `is_full` to `IndexSet`
- Added `is_full` to `LinearMap`
- Added infallible conversions from arrays to `Vec`.
- Added `Vec::spare_capacity_mut`.
- Added `Extend` impls for `Deque`.

View File

@ -227,6 +227,27 @@ where
self.len() == 0
}
/// Returns true if the map is full.
///
/// Computes in *O*(1) time.
///
/// # Examples
///
/// ```
/// use heapless::LinearMap;
///
/// let mut a: LinearMap<_, _, 4> = LinearMap::new();
/// assert!(!a.is_full());
/// a.insert(1, "a").unwrap();
/// a.insert(2, "b").unwrap();
/// a.insert(3, "c").unwrap();
/// a.insert(4, "d").unwrap();
/// assert!(a.is_full());
/// ```
pub fn is_full(&self) -> bool {
self.len() == self.capacity()
}
/// An iterator visiting all key-value pairs in arbitrary order.
///
/// # Examples