Remove BinaryHeap::{push_pop,replace}
[unstable, deprecated since 1.13.0]
This commit is contained in:
parent
a76274e533
commit
a724ff90e7
@ -103,7 +103,6 @@
|
||||
- [as_c_str](library-features/as-c-str.md)
|
||||
- [as_unsafe_cell](library-features/as-unsafe-cell.md)
|
||||
- [ascii_ctype](library-features/ascii-ctype.md)
|
||||
- [binary_heap_extras](library-features/binary-heap-extras.md)
|
||||
- [binary_heap_peek_mut_pop](library-features/binary-heap-peek-mut-pop.md)
|
||||
- [borrow_state](library-features/borrow-state.md)
|
||||
- [box_heap](library-features/box-heap.md)
|
||||
|
@ -1,7 +0,0 @@
|
||||
# `binary_heap_extras`
|
||||
|
||||
The tracking issue for this feature is: [#28147]
|
||||
|
||||
[#28147]: https://github.com/rust-lang/rust/issues/28147
|
||||
|
||||
------------------------
|
@ -555,82 +555,6 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
self.sift_up(0, old_len);
|
||||
}
|
||||
|
||||
/// Pushes an item onto the binary heap, then pops the greatest item off the queue in
|
||||
/// an optimized fashion.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(binary_heap_extras)]
|
||||
/// #![allow(deprecated)]
|
||||
///
|
||||
/// use std::collections::BinaryHeap;
|
||||
/// let mut heap = BinaryHeap::new();
|
||||
/// heap.push(1);
|
||||
/// heap.push(5);
|
||||
///
|
||||
/// assert_eq!(heap.push_pop(3), 5);
|
||||
/// assert_eq!(heap.push_pop(9), 9);
|
||||
/// assert_eq!(heap.len(), 2);
|
||||
/// assert_eq!(heap.peek(), Some(&3));
|
||||
/// ```
|
||||
#[unstable(feature = "binary_heap_extras",
|
||||
reason = "needs to be audited",
|
||||
issue = "28147")]
|
||||
#[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
|
||||
pub fn push_pop(&mut self, mut item: T) -> T {
|
||||
match self.data.get_mut(0) {
|
||||
None => return item,
|
||||
Some(top) => {
|
||||
if *top > item {
|
||||
swap(&mut item, top);
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.sift_down(0);
|
||||
item
|
||||
}
|
||||
|
||||
/// Pops the greatest item off the binary heap, then pushes an item onto the queue in
|
||||
/// an optimized fashion. The push is done regardless of whether the binary heap
|
||||
/// was empty.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(binary_heap_extras)]
|
||||
/// #![allow(deprecated)]
|
||||
///
|
||||
/// use std::collections::BinaryHeap;
|
||||
/// let mut heap = BinaryHeap::new();
|
||||
///
|
||||
/// assert_eq!(heap.replace(1), None);
|
||||
/// assert_eq!(heap.replace(3), Some(1));
|
||||
/// assert_eq!(heap.len(), 1);
|
||||
/// assert_eq!(heap.peek(), Some(&3));
|
||||
/// ```
|
||||
#[unstable(feature = "binary_heap_extras",
|
||||
reason = "needs to be audited",
|
||||
issue = "28147")]
|
||||
#[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
|
||||
pub fn replace(&mut self, mut item: T) -> Option<T> {
|
||||
if !self.is_empty() {
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.sift_down(0);
|
||||
Some(item)
|
||||
} else {
|
||||
self.push(item);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes the `BinaryHeap` and returns the underlying vector
|
||||
/// in arbitrary order.
|
||||
///
|
||||
|
@ -152,36 +152,6 @@ fn test_push_unique() {
|
||||
assert!(*heap.peek().unwrap() == box 103);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_push_pop() {
|
||||
let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.push_pop(6), 6);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.push_pop(0), 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.push_pop(4), 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.push_pop(1), 4);
|
||||
assert_eq!(heap.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_replace() {
|
||||
let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.replace(6).unwrap(), 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.replace(0).unwrap(), 6);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.replace(4).unwrap(), 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert_eq!(heap.replace(1).unwrap(), 4);
|
||||
assert_eq!(heap.len(), 5);
|
||||
}
|
||||
|
||||
fn check_to_vec(mut data: Vec<i32>) {
|
||||
let heap = BinaryHeap::from(data.clone());
|
||||
let mut v = heap.clone().into_vec();
|
||||
@ -227,13 +197,6 @@ fn test_empty_peek_mut() {
|
||||
assert!(empty.peek_mut().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_empty_replace() {
|
||||
let mut heap = BinaryHeap::new();
|
||||
assert!(heap.replace(5).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_iter() {
|
||||
let xs = vec![9, 8, 7, 6, 5, 4, 3, 2, 1];
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#![deny(warnings)]
|
||||
|
||||
#![feature(binary_heap_extras)]
|
||||
#![feature(binary_heap_peek_mut_pop)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
@ -9,8 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(binary_heap_extras)]
|
||||
|
||||
use std::collections::BinaryHeap;
|
||||
|
||||
fn make_pq() -> BinaryHeap<isize> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user