Compare commits
No commits in common. "fec9ccffc69dc65c4fd24fcbf9f1f0ff402e2b2e" and "7184ddb9b0b0b125be40c54c4d8f5c9205dacbe4" have entirely different histories.
fec9ccffc6
...
7184ddb9b0
3 changed files with 6 additions and 118 deletions
|
@ -1,53 +0,0 @@
|
||||||
use std::{collections::HashMap, hash::Hash};
|
|
||||||
|
|
||||||
use crate::backing::{containers::Pair, indexed::IndexedBacking, pure::PureBacking};
|
|
||||||
|
|
||||||
pub struct IndexedBinaryHeap<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> {
|
|
||||||
data: Vec<Pair<D, P>>,
|
|
||||||
indices: HashMap<D, usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> IndexedBinaryHeap<D, P> {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
data: Vec::new(),
|
|
||||||
indices: HashMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: Hash + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> FromIterator<Pair<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 {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,4 @@
|
||||||
/// Data structures for the "indexed" min-queues, supporting priority updates and arbitrary removals, but no duplicates
|
/// Data structures for the "indexed" min-queues, supporting priority updates and arbitrary removals, but no duplicates
|
||||||
mod binary_heap;
|
|
||||||
|
|
||||||
pub use binary_heap::IndexedBinaryHeap;
|
|
||||||
|
|
||||||
use super::{containers::Pair, pure::PureBacking};
|
use super::{containers::Pair, pure::PureBacking};
|
||||||
|
|
||||||
/// A data structure usable for backing an "indexed" queue
|
/// A data structure usable for backing an "indexed" queue
|
||||||
|
@ -10,7 +6,7 @@ pub trait IndexedBacking<D: Clone + Send + Sync, P: PartialOrd + Clone + Send +
|
||||||
PureBacking<Pair<D, P>>
|
PureBacking<Pair<D, P>>
|
||||||
{
|
{
|
||||||
/// Update an item's priority
|
/// Update an item's priority
|
||||||
fn update(&mut self, data: D, priority: P) -> bool;
|
fn update(data: D, priority: P) -> Result<(), ()>;
|
||||||
/// Remove an item from the queue
|
/// Remove an item from the queue
|
||||||
fn remove(&mut self, data: D) -> bool;
|
fn remove(data: D) -> bool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +1,12 @@
|
||||||
use pyo3::{
|
use pyo3::prelude::*;
|
||||||
exceptions::{PyIndexError, PyStopIteration},
|
|
||||||
prelude::*,
|
|
||||||
types::PyType,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::backing::indexed::IndexedBacking;
|
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct IndexedQueue {
|
pub struct IndexedQueue {}
|
||||||
backing: Box<dyn IndexedBacking<Py<PyAny>, f64>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl IndexedQueue {
|
impl IndexedQueue {
|
||||||
#[new]
|
#[new]
|
||||||
#[pyo3(signature = (items=None))]
|
fn new() -> Self {
|
||||||
fn new(items: Option<Py<PyAny>>) -> PyResult<Self> {
|
Self {}
|
||||||
if let Some(py_object) = items {
|
|
||||||
todo!()
|
|
||||||
} else {
|
|
||||||
todo!() // TBD: Determine best way to make Python object hashable from Rust
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __setitem__(mut self_: PyRefMut<'_, Self>, key: Py<PyAny>, value: Py<PyAny>) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __delitem__(mut self_: PyRefMut<'_, Self>, key: Py<PyAny>) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __contains__(mut self_: PyRefMut<'_, Self>, key: Py<PyAny>) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Enables generic typing
|
|
||||||
#[classmethod]
|
|
||||||
fn __class_getitem__(cls_: Bound<'_, PyType>, _key: Py<PyAny>) -> Bound<'_, PyType> {
|
|
||||||
cls_
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __len__(self_: PyRef<'_, Self>) -> usize {
|
|
||||||
self_.backing.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __iter__(self_: PyRef<'_, Self>) -> PyRef<'_, Self> {
|
|
||||||
self_
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __next__(mut self_: PyRefMut<'_, Self>) -> PyResult<Py<PyAny>> {
|
|
||||||
if let Some(item) = self_.backing.pop() {
|
|
||||||
Ok(item.data())
|
|
||||||
} else {
|
|
||||||
Err(PyErr::new::<PyStopIteration, _>(()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop(mut self_: PyRefMut<'_, Self>) -> PyResult<Py<PyAny>> {
|
|
||||||
if let Some(item) = self_.backing.pop() {
|
|
||||||
Ok(item.data())
|
|
||||||
} else {
|
|
||||||
Err(PyErr::new::<PyIndexError, _>(()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue