Rename Item -> containers::Pair
This commit is contained in:
parent
e424dd42f5
commit
ee004bac19
5 changed files with 20 additions and 17 deletions
3
src/backing/containers/mod.rs
Normal file
3
src/backing/containers/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod pair;
|
||||
|
||||
pub use pair::Pair;
|
|
@ -3,12 +3,12 @@ use std::cmp::Ordering;
|
|||
/// Helper struct to associate an item with its priority
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
// I mean I guess P should be Ord but I want to use f64 so whatever
|
||||
pub struct Item<D: Clone, P: PartialOrd + Clone> {
|
||||
pub struct Pair<D: Clone, P: PartialOrd + Clone> {
|
||||
data: D,
|
||||
priority: P,
|
||||
}
|
||||
|
||||
impl<D: Clone, P: PartialOrd + Clone> Item<D, P> {
|
||||
impl<D: Clone, P: PartialOrd + Clone> Pair<D, P> {
|
||||
/// Creates a new instance
|
||||
pub fn new(data: D, priority: P) -> Self {
|
||||
Self { data, priority }
|
||||
|
@ -21,7 +21,7 @@ impl<D: Clone, P: PartialOrd + Clone> Item<D, P> {
|
|||
}
|
||||
|
||||
// The relevant Ord implementations are based just on the priority
|
||||
impl<D: Clone, P: PartialOrd + Clone> Ord for Item<D, P> {
|
||||
impl<D: Clone, P: PartialOrd + Clone> Ord for Pair<D, P> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
// Yeah this is bad design
|
||||
// My excuse is that i'm still learning Rust
|
||||
|
@ -31,16 +31,16 @@ impl<D: Clone, P: PartialOrd + Clone> Ord for Item<D, P> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<D: Clone, P: PartialOrd + Clone> PartialOrd for Item<D, P> {
|
||||
impl<D: Clone, P: PartialOrd + Clone> PartialOrd for Pair<D, P> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.priority.partial_cmp(&other.priority)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Clone, P: PartialOrd + Clone> PartialEq for Item<D, P> {
|
||||
impl<D: Clone, P: PartialOrd + Clone> PartialEq for Pair<D, P> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.priority == other.priority
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Clone, P: PartialOrd + Clone> Eq for Item<D, P> {}
|
||||
impl<D: Clone, P: PartialOrd + Clone> Eq for Pair<D, P> {}
|
|
@ -1,9 +1,9 @@
|
|||
/// Data structures for the "indexed" min-queues, supporting priority updates and arbitrary removals, but no duplicates
|
||||
use super::{item::Item, pure::PureBacking};
|
||||
use super::{containers::Pair, pure::PureBacking};
|
||||
|
||||
/// A data structure usable for backing an "indexed" queue
|
||||
pub trait IndexedBacking<D: Clone + Send + Sync, P: Ord + Clone + Send + Sync>:
|
||||
PureBacking<Item<D, P>>
|
||||
PureBacking<Pair<D, P>>
|
||||
{
|
||||
/// Update an item's priority
|
||||
fn update(data: D, priority: P) -> Result<(), ()>;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub mod containers;
|
||||
pub mod indexed;
|
||||
pub mod item;
|
||||
pub mod pure;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue