mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-28 21:10:28 +00:00
Merge pull request #513 from sourcebox/additions
Added `is_full` function to `BinaryHeap`, `IndexMap`, `IndexSet` and `LinearMap`
This commit is contained in:
commit
69add426a4
@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Added `format` macro.
|
||||
- Added `String::from_utf16`.
|
||||
- Added `is_full`, `recent_index`, `oldest`, and `oldest_index` to `HistoryBuffer`
|
||||
- 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`.
|
||||
|
@ -262,6 +262,26 @@ where
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Checks if the binary heap is full.
|
||||
///
|
||||
/// ```
|
||||
/// use heapless::binary_heap::{BinaryHeap, Max};
|
||||
///
|
||||
/// let mut heap: BinaryHeap<_, Max, 4> = BinaryHeap::new();
|
||||
///
|
||||
/// assert!(!heap.is_full());
|
||||
///
|
||||
/// heap.push(1).unwrap();
|
||||
/// heap.push(2).unwrap();
|
||||
/// heap.push(3).unwrap();
|
||||
/// heap.push(4).unwrap();
|
||||
///
|
||||
/// assert!(heap.is_full());
|
||||
/// ```
|
||||
pub fn is_full(&self) -> bool {
|
||||
self.len() == self.capacity()
|
||||
}
|
||||
|
||||
/// Returns an iterator visiting all values in the underlying vector, in arbitrary order.
|
||||
///
|
||||
/// ```
|
||||
|
@ -926,6 +926,25 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Returns true if the map is full.
|
||||
///
|
||||
/// Computes in *O*(1) time.
|
||||
///
|
||||
/// ```
|
||||
/// use heapless::FnvIndexMap;
|
||||
///
|
||||
/// let mut a = FnvIndexMap::<_, _, 4>::new();
|
||||
/// assert!(!a.is_full());
|
||||
/// a.insert(1, "a");
|
||||
/// a.insert(2, "b");
|
||||
/// a.insert(3, "c");
|
||||
/// a.insert(4, "d");
|
||||
/// assert!(a.is_full());
|
||||
/// ```
|
||||
pub fn is_full(&self) -> bool {
|
||||
self.len() == self.capacity()
|
||||
}
|
||||
|
||||
/// Remove all key-value pairs in the map, while preserving its capacity.
|
||||
///
|
||||
/// Computes in *O*(n) time.
|
||||
|
@ -180,6 +180,25 @@ impl<T, S, const N: usize> IndexSet<T, S, N> {
|
||||
self.map.is_empty()
|
||||
}
|
||||
|
||||
/// Returns `true` if the set is full.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use heapless::FnvIndexSet;
|
||||
///
|
||||
/// let mut v: FnvIndexSet<_, 4> = FnvIndexSet::new();
|
||||
/// assert!(!v.is_full());
|
||||
/// v.insert(1).unwrap();
|
||||
/// v.insert(2).unwrap();
|
||||
/// v.insert(3).unwrap();
|
||||
/// v.insert(4).unwrap();
|
||||
/// assert!(v.is_full());
|
||||
/// ```
|
||||
pub fn is_full(&self) -> bool {
|
||||
self.map.is_full()
|
||||
}
|
||||
|
||||
/// Clears the set, removing all values.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user