Add PyItem container
Also reduce queue item trait bound from Ord to just PartialOrd
This commit is contained in:
parent
ee004bac19
commit
38a544db76
8 changed files with 91 additions and 32 deletions
|
@ -2,12 +2,6 @@ use std::fmt;
|
|||
|
||||
use super::PureBacking;
|
||||
|
||||
/// A binary min-heap backed by an array
|
||||
#[derive(Debug)]
|
||||
pub struct BinaryHeap<T: Ord + Clone + Send + Sync> {
|
||||
data: Vec<T>,
|
||||
}
|
||||
|
||||
/// Indicates why a sift failed
|
||||
#[derive(Debug, Clone)]
|
||||
struct SiftError {
|
||||
|
@ -33,7 +27,13 @@ impl fmt::Display for SiftError {
|
|||
/// Whether a sift operation succeeded
|
||||
type SiftResult = Result<(), SiftError>;
|
||||
|
||||
impl<T: Ord + Clone + Send + Sync> BinaryHeap<T> {
|
||||
/// A binary min-heap backed by an array
|
||||
#[derive(Debug)]
|
||||
pub struct BinaryHeap<T: PartialOrd + Clone + Send + Sync> {
|
||||
data: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: PartialOrd + Clone + Send + Sync> BinaryHeap<T> {
|
||||
/// Instantiates a new (empty) binary heap
|
||||
pub fn new() -> Self {
|
||||
Self { data: vec![] }
|
||||
|
@ -108,7 +108,7 @@ impl<T: Ord + Clone + Send + Sync> BinaryHeap<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Ord + Clone + Send + Sync> FromIterator<T> for BinaryHeap<T> {
|
||||
impl<T: PartialOrd + Clone + Send + Sync> FromIterator<T> for BinaryHeap<T> {
|
||||
fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self {
|
||||
let mut this = Self {
|
||||
data: Vec::from_iter(iter),
|
||||
|
@ -120,7 +120,7 @@ impl<T: Ord + Clone + Send + Sync> FromIterator<T> for BinaryHeap<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Ord + Clone + Send + Sync> PureBacking<T> for BinaryHeap<T> {
|
||||
impl<T: PartialOrd + Clone + Send + Sync> PureBacking<T> for BinaryHeap<T> {
|
||||
fn add(&mut self, item: T) {
|
||||
// Append item
|
||||
self.data.push(item);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue