Simplify IndexedQueue API
Although similar to PureQueue, it doesn't make sense to use the exact same signatures. Also don't make API users use Pair<D, P>.
This commit is contained in:
parent
16c1a4d390
commit
63515e2314
3 changed files with 40 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
use crate::backing::{containers::Pair, indexed::IndexedBacking, pure::PureBacking};
|
||||
use crate::backing::{containers::Pair, indexed::IndexedBacking};
|
||||
|
||||
pub struct IndexedBinaryHeap<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> {
|
||||
data: Vec<Pair<D, P>>,
|
||||
|
@ -16,26 +16,10 @@ impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> Indexed
|
|||
}
|
||||
}
|
||||
|
||||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> FromIterator<Pair<D, P>>
|
||||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> FromIterator<(D, P)>
|
||||
for IndexedBinaryHeap<D, P>
|
||||
{
|
||||
fn from_iter<T: IntoIterator<Item = Pair<D, P>>>(iter: T) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> PureBacking<Pair<D, P>>
|
||||
for IndexedBinaryHeap<D, P>
|
||||
{
|
||||
fn add(&mut self, item: Pair<D, P>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn pop(&mut self) -> Option<Pair<D, P>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
fn from_iter<T: IntoIterator<Item = (D, P)>>(iter: T) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -43,15 +27,23 @@ impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> PureBac
|
|||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> IndexedBacking<D, P>
|
||||
for IndexedBinaryHeap<D, P>
|
||||
{
|
||||
fn update(&mut self, data: D, priority: P) -> bool {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove(&mut self, data: D) -> bool {
|
||||
fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn contains(&self, data: &D) -> bool {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set(&mut self, data: D, priority: P) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove(&mut self, data: D) -> Option<P> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn pop(&mut self) -> Option<D> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,18 @@ mod binary_heap;
|
|||
|
||||
pub use binary_heap::IndexedBinaryHeap;
|
||||
|
||||
use super::{containers::Pair, pure::PureBacking};
|
||||
|
||||
/// A data structure usable for backing an "indexed" queue
|
||||
pub trait IndexedBacking<D: Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync>:
|
||||
PureBacking<Pair<D, P>>
|
||||
Send + Sync
|
||||
{
|
||||
/// Update an item's priority
|
||||
fn update(&mut self, data: D, priority: P) -> bool;
|
||||
/// Remove an item from the queue
|
||||
fn remove(&mut self, data: D) -> bool;
|
||||
/// The length of the queue
|
||||
fn len(&self) -> usize;
|
||||
/// Check if an item is already in the queue
|
||||
fn contains(&self, data: &D) -> bool;
|
||||
/// Set an item's priority, will update if the item is already enqueued
|
||||
fn set(&mut self, data: D, priority: P);
|
||||
/// Remove a specific item from the queue, returns the associated priority if the item existed
|
||||
fn remove(&mut self, data: D) -> Option<P>;
|
||||
/// Remove the top of the queue, if it exists
|
||||
fn pop(&mut self) -> Option<D>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue