Address review comments and fix tests

This commit is contained in:
Max Heller 2026-01-30 09:55:34 -05:00
parent 9928723bff
commit bae7a199f1
No known key found for this signature in database
4 changed files with 6 additions and 5 deletions

View file

@ -656,14 +656,15 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
/// # Examples
///
/// ```
/// #![feature(binary_heap_pop_if)]
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::from([1, 2]);
/// let pred = |x: &i32| *x % 2 == 0;
///
/// assert_eq!(heap.pop_if(pred), Some(2));
/// assert_eq!(heap, BinaryHeap::from([1]));
/// assert_eq!(heap.as_slice(), [1]);
/// assert_eq!(heap.pop_if(pred), None);
/// assert_eq!(heap, BinaryHeap::from([1]));
/// assert_eq!(heap.as_slice(), [1]);
/// ```
///
/// # Time complexity
@ -671,7 +672,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
/// The worst case cost of `pop_if` on a heap containing *n* elements is *O*(log(*n*)).
#[unstable(feature = "binary_heap_pop_if", issue = "151828")]
pub fn pop_if(&mut self, predicate: impl FnOnce(&T) -> bool) -> Option<T> {
let first = self.data.first()?;
let first = self.peek()?;
if predicate(first) { self.pop() } else { None }
}

View file

@ -17,7 +17,6 @@
#![feature(allocator_api)]
#![feature(array_into_iter_constructors)]
#![feature(assert_matches)]
#![feature(binary_heap_pop_if)]
#![feature(box_vec_non_null)]
#![feature(char_internals)]
#![feature(const_alloc_error)]

View file

@ -145,7 +145,7 @@ fn test_pop_if() {
while let Some(popped) = heap.pop_if(|x| *x > 2) {
assert_eq!(popped, sorted.pop().unwrap());
}
assert_eq!(heap.into_sorted_vec(), vec![1, 2]);
assert_eq!(heap.into_sorted_vec(), vec![0, 1, 2]);
}
#[test]

View file

@ -1,4 +1,5 @@
#![feature(allocator_api)]
#![feature(binary_heap_pop_if)]
#![feature(const_heap)]
#![feature(deque_extend_front)]
#![feature(iter_array_chunks)]