Extract Sift{Error, Result} from pure BinaryHeap
This commit is contained in:
parent
ebfce09c0e
commit
818e83d260
3 changed files with 29 additions and 26 deletions
|
@ -1,5 +1,7 @@
|
||||||
mod pair;
|
mod pair;
|
||||||
mod py_item;
|
mod py_item;
|
||||||
|
mod sift_result;
|
||||||
|
|
||||||
pub use pair::Pair;
|
pub use pair::Pair;
|
||||||
pub use py_item::PyItem;
|
pub use py_item::PyItem;
|
||||||
|
pub use sift_result::{SiftError, SiftResult};
|
||||||
|
|
26
src/backing/containers/sift_result.rs
Normal file
26
src/backing/containers/sift_result.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use std::fmt::{Display, Formatter, Result as fmtResult};
|
||||||
|
|
||||||
|
/// Indicates why a sift failed
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct SiftError {
|
||||||
|
/// The index that couldn't be sifted
|
||||||
|
index: usize,
|
||||||
|
/// The length of the array
|
||||||
|
len: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SiftError {
|
||||||
|
/// Instantiates a `SiftError`
|
||||||
|
pub fn new(index: usize, len: usize) -> Self {
|
||||||
|
Self { index, len }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for SiftError {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> fmtResult {
|
||||||
|
write!(f, "Could not sift index {} of {}", self.index, self.len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether a sift operation succeeded
|
||||||
|
pub type SiftResult = Result<(), SiftError>;
|
|
@ -1,32 +1,7 @@
|
||||||
use std::fmt;
|
use crate::backing::containers::{SiftError, SiftResult};
|
||||||
|
|
||||||
use super::PureBacking;
|
use super::PureBacking;
|
||||||
|
|
||||||
/// Indicates why a sift failed
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
struct SiftError {
|
|
||||||
/// The index that couldn't be sifted
|
|
||||||
index: usize,
|
|
||||||
/// The length of the array
|
|
||||||
len: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SiftError {
|
|
||||||
/// Instantiates a `SiftError`
|
|
||||||
fn new(index: usize, len: usize) -> Self {
|
|
||||||
Self { index, len }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for SiftError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "Could not sift index {} of {}", self.index, self.len)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether a sift operation succeeded
|
|
||||||
type SiftResult = Result<(), SiftError>;
|
|
||||||
|
|
||||||
/// A binary min-heap backed by an array
|
/// A binary min-heap backed by an array
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BinaryHeap<T: PartialOrd + Clone + Send + Sync> {
|
pub struct BinaryHeap<T: PartialOrd + Clone + Send + Sync> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue