Scaffold IndexedQueue and IndexedBinaryHeap
This commit is contained in:
parent
64030bd349
commit
fec9ccffc6
3 changed files with 116 additions and 4 deletions
|
@ -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<dyn IndexedBacking<Py<PyAny>, f64>>,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl IndexedQueue {
|
||||
#[new]
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
#[pyo3(signature = (items=None))]
|
||||
fn new(items: Option<Py<PyAny>>) -> PyResult<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