diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b85c38b..e11b8b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/src/linear_map.rs b/src/linear_map.rs index 28f4e83d..d6e74df4 100644 --- a/src/linear_map.rs +++ b/src/linear_map.rs @@ -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