@@ -159,7 +159,7 @@ pub type BinaryHeapView<T, K> = BinaryHeapInner<T, K, ViewVecStorage<T>>;
159
159
160
160
impl < T , K , const N : usize > BinaryHeap < T , K , N > {
161
161
/* Constructors */
162
- /// Creates an empty BinaryHeap as a $K-heap.
162
+ /// Creates an empty ` BinaryHeap` as a $K-heap.
163
163
///
164
164
/// ```
165
165
/// use heapless::binary_heap::{BinaryHeap, Max};
@@ -184,14 +184,16 @@ impl<T, K, const N: usize> BinaryHeap<T, K, N> {
184
184
pub fn into_vec ( self ) -> Vec < T , N > {
185
185
self . data
186
186
}
187
+ }
187
188
189
+ impl < T , K , S : VecStorage < T > > BinaryHeapInner < T , K , S > {
188
190
/// Get a reference to the `BinaryHeap`, erasing the `N` const-generic.
189
191
pub fn as_view ( & self ) -> & BinaryHeapView < T , K > {
190
- self
192
+ S :: as_binary_heap_view ( self )
191
193
}
192
194
/// Get a mutable reference to the `BinaryHeap`, erasing the `N` const-generic.
193
195
pub fn as_mut_view ( & mut self ) -> & mut BinaryHeapView < T , K > {
194
- self
196
+ S :: as_binary_heap_mut_view ( self )
195
197
}
196
198
}
197
199
@@ -203,7 +205,7 @@ where
203
205
/* Public API */
204
206
/// Returns the capacity of the binary heap.
205
207
pub fn capacity ( & self ) -> usize {
206
- self . data . storage_capacity ( )
208
+ self . data . capacity ( )
207
209
}
208
210
209
211
/// Drops all items from the binary heap.
@@ -222,7 +224,7 @@ where
222
224
/// assert!(heap.is_empty());
223
225
/// ```
224
226
pub fn clear ( & mut self ) {
225
- self . data . clear ( )
227
+ self . data . clear ( ) ;
226
228
}
227
229
228
230
/// Returns the length of the binary heap.
@@ -386,7 +388,24 @@ where
386
388
387
389
/// Removes the *top* (greatest if max-heap, smallest if min-heap) item from the binary heap and
388
390
/// returns it, without checking if the binary heap is empty.
389
- #[ allow( clippy:: missing_safety_doc) ] // TODO
391
+ ///
392
+ /// # Safety
393
+ ///
394
+ /// The binary heap must not be empty.
395
+ ///
396
+ /// # Example
397
+ ///
398
+ /// ```
399
+ /// use heapless::binary_heap::{BinaryHeap, Max};
400
+ ///
401
+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
402
+ /// heap.push(42)?;
403
+ ///
404
+ /// // SAFETY: We just pushed a number onto the heap, so it cannot be empty.
405
+ /// let val = unsafe { heap.pop_unchecked() };
406
+ /// assert_eq!(val, 42);
407
+ /// # Ok::<(), u8>(())
408
+ /// ```
390
409
pub unsafe fn pop_unchecked ( & mut self ) -> T {
391
410
let mut item = self . data . pop_unchecked ( ) ;
392
411
@@ -420,7 +439,23 @@ where
420
439
}
421
440
422
441
/// Pushes an item onto the binary heap without first checking if it's full.
423
- #[ allow( clippy:: missing_safety_doc) ] // TODO
442
+ ///
443
+ /// # Safety
444
+ ///
445
+ /// The binary heap must not be full.
446
+ ///
447
+ /// # Example
448
+ ///
449
+ /// ```
450
+ /// use heapless::binary_heap::{BinaryHeap, Max};
451
+ ///
452
+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
453
+ ///
454
+ /// // SAFETY: We just created an empty heap of size 8, so it cannot be full.
455
+ /// unsafe { heap.push_unchecked(42) };
456
+ /// assert_eq!(heap.len(), 1);
457
+ /// assert_eq!(heap.peek(), Some(&42));
458
+ /// ```
424
459
pub unsafe fn push_unchecked ( & mut self , item : T ) {
425
460
let old_len = self . len ( ) ;
426
461
self . data . push_unchecked ( item) ;
@@ -596,14 +631,14 @@ where
596
631
}
597
632
}
598
633
599
- impl < ' a , T , K , S > PeekMutInner < ' a , T , K , S >
634
+ impl < T , K , S > PeekMutInner < ' _ , T , K , S >
600
635
where
601
636
T : Ord ,
602
637
K : Kind ,
603
638
S : VecStorage < T > + ?Sized ,
604
639
{
605
640
/// Removes the peeked value from the heap and returns it.
606
- pub fn pop ( mut this : PeekMutInner < ' a , T , K , S > ) -> T {
641
+ pub fn pop ( mut this : Self ) -> T {
607
642
let value = this. heap . pop ( ) . unwrap ( ) ;
608
643
this. sift = false ;
609
644
value
0 commit comments