Skip to content

Commit 2ef05ed

Browse files
committed
Added is_full to IndexMap
1 parent 0df6e11 commit 2ef05ed

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Added `String::from_utf16`.
1414
- Added `is_full`, `recent_index`, `oldest`, and `oldest_index` to `HistoryBuffer`
1515
- Added `is_full` to `BinaryHeap`
16+
- Added `is_full` to `IndexMap`
1617
- Added infallible conversions from arrays to `Vec`.
1718
- Added `Vec::spare_capacity_mut`.
1819
- Added `Extend` impls for `Deque`.

src/indexmap.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,25 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {
926926
self.len() == 0
927927
}
928928

929+
/// Returns true if the map is full.
930+
///
931+
/// Computes in *O*(1) time.
932+
///
933+
/// ```
934+
/// use heapless::FnvIndexMap;
935+
///
936+
/// let mut a = FnvIndexMap::<_, _, 4>::new();
937+
/// assert!(!a.is_full());
938+
/// a.insert(1, "a");
939+
/// a.insert(2, "b");
940+
/// a.insert(3, "c");
941+
/// a.insert(4, "d");
942+
/// assert!(a.is_full());
943+
/// ```
944+
pub fn is_full(&self) -> bool {
945+
self.len() == self.capacity()
946+
}
947+
929948
/// Remove all key-value pairs in the map, while preserving its capacity.
930949
///
931950
/// Computes in *O*(n) time.

0 commit comments

Comments
 (0)