diff --git a/src/backing/indexed/binary_heap.rs b/src/backing/indexed/binary_heap.rs new file mode 100644 index 0000000..e5ec273 --- /dev/null +++ b/src/backing/indexed/binary_heap.rs @@ -0,0 +1,53 @@ +use std::{collections::HashMap, hash::Hash}; + +use crate::backing::{containers::Pair, indexed::IndexedBacking, pure::PureBacking}; + +pub struct IndexedBinaryHeap { + data: Vec>, + indices: HashMap, +} + +impl IndexedBinaryHeap { + pub fn new() -> Self { + Self { + data: Vec::new(), + indices: HashMap::new(), + } + } +} + +impl FromIterator> + for IndexedBinaryHeap +{ + fn from_iter>>(iter: T) -> Self { + todo!() + } +} + +impl PureBacking> + for IndexedBinaryHeap +{ + fn add(&mut self, item: Pair) { + todo!() + } + + fn pop(&mut self) -> Option> { + todo!() + } + + fn len(&self) -> usize { + todo!() + } +} + +impl IndexedBacking + for IndexedBinaryHeap +{ + fn update(&mut self, data: D, priority: P) -> bool { + todo!() + } + + fn remove(&mut self, data: D) -> bool { + todo!() + } +} diff --git a/src/backing/indexed/mod.rs b/src/backing/indexed/mod.rs index 6ab0e7c..1a39cb0 100644 --- a/src/backing/indexed/mod.rs +++ b/src/backing/indexed/mod.rs @@ -1,4 +1,8 @@ /// 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}; /// A data structure usable for backing an "indexed" queue diff --git a/src/queue/indexed.rs b/src/queue/indexed.rs index 086ad0f..c1f433f 100644 --- a/src/queue/indexed.rs +++ b/src/queue/indexed.rs @@ -1,12 +1,67 @@ -use pyo3::prelude::*; +use pyo3::{ + exceptions::{PyIndexError, PyStopIteration}, + prelude::*, + types::PyType, +}; + +use crate::backing::indexed::IndexedBacking; #[pyclass] -pub struct IndexedQueue {} +pub struct IndexedQueue { + backing: Box, f64>>, +} #[pymethods] impl IndexedQueue { #[new] - fn new() -> Self { - Self {} + #[pyo3(signature = (items=None))] + fn new(items: Option>) -> PyResult { + 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, value: Py) { + todo!() + } + + fn __delitem__(mut self_: PyRefMut<'_, Self>, key: Py) { + todo!() + } + + fn __contains__(mut self_: PyRefMut<'_, Self>, key: Py) { + todo!() + } + + /// Enables generic typing + #[classmethod] + fn __class_getitem__(cls_: Bound<'_, PyType>, _key: Py) -> 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> { + if let Some(item) = self_.backing.pop() { + Ok(item.data()) + } else { + Err(PyErr::new::(())) + } + } + + fn pop(mut self_: PyRefMut<'_, Self>) -> PyResult> { + if let Some(item) = self_.backing.pop() { + Ok(item.data()) + } else { + Err(PyErr::new::(())) + } } }