Skip to content

Commit 0df6e11

Browse files
committed
Added is_full to BinaryHeap
1 parent f09c219 commit 0df6e11

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

CHANGELOG.md

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

src/binary_heap.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@ where
262262
self.len() == 0
263263
}
264264

265+
/// Checks if the binary heap is full.
266+
///
267+
/// ```
268+
/// use heapless::binary_heap::{BinaryHeap, Max};
269+
///
270+
/// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
271+
///
272+
/// assert!(!heap.is_full());
273+
///
274+
/// heap.push(1).unwrap();
275+
/// heap.push(2).unwrap();
276+
/// heap.push(3).unwrap();
277+
/// heap.push(4).unwrap();
278+
/// heap.push(5).unwrap();
279+
/// heap.push(6).unwrap();
280+
/// heap.push(7).unwrap();
281+
/// heap.push(8).unwrap();
282+
///
283+
/// assert!(heap.is_full());
284+
/// ```
285+
pub fn is_full(&self) -> bool {
286+
self.len() == self.capacity()
287+
}
288+
265289
/// Returns an iterator visiting all values in the underlying vector, in arbitrary order.
266290
///
267291
/// ```

0 commit comments

Comments
 (0)