Skip to content

Commit c603323

Browse files
committed
Added is_full to LinearMap
1 parent f6b9487 commit c603323

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Added `is_full` to `BinaryHeap`
1616
- Added `is_full` to `IndexMap`
1717
- Added `is_full` to `IndexSet`
18+
- Added `is_full` to `LinearMap`
1819
- Added infallible conversions from arrays to `Vec`.
1920
- Added `Vec::spare_capacity_mut`.
2021
- Added `Extend` impls for `Deque`.

src/linear_map.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,27 @@ where
227227
self.len() == 0
228228
}
229229

230+
/// Returns true if the map is full.
231+
///
232+
/// Computes in *O*(1) time.
233+
///
234+
/// # Examples
235+
///
236+
/// ```
237+
/// use heapless::LinearMap;
238+
///
239+
/// let mut a: LinearMap<_, _, 4> = LinearMap::new();
240+
/// assert!(!a.is_full());
241+
/// a.insert(1, "a").unwrap();
242+
/// a.insert(2, "b").unwrap();
243+
/// a.insert(3, "c").unwrap();
244+
/// a.insert(4, "d").unwrap();
245+
/// assert!(a.is_full());
246+
/// ```
247+
pub fn is_full(&self) -> bool {
248+
self.len() == self.capacity()
249+
}
250+
230251
/// An iterator visiting all key-value pairs in arbitrary order.
231252
///
232253
/// # Examples

0 commit comments

Comments
 (0)