Update Rust structure to better match proposed Python API

This commit is contained in:
Michael Bradley 2025-01-08 23:00:24 +13:00
parent b4ca806d76
commit ffe6a76241
Signed by: MichaelBradley
SSH key fingerprint: SHA256:cj/YZ5VT+QOKncqSkx+ibKTIn0Obg7OIzwzl9BL8EO8
6 changed files with 18 additions and 18 deletions

View file

@ -0,0 +1,12 @@
/// Data structures for the "indexed" min-queues, supporting priority updates and arbitrary removals, but no duplicates
use super::{item::Item, 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>>
{
/// Update an item's priority
fn update(data: D, priority: P) -> Result<(), ()>;
/// Remove an item from the queue
fn remove(data: D) -> bool;
}

View file

@ -1,12 +0,0 @@
/// Data structures for the "keyed" min-queues, supporting priority updates and arbitrary removals, but no duplicates
use super::{item::Item, pure::PureBacking};
/// A data structure usable for backing a "keyed" queue
pub trait KeyedBacking<D: Clone + Send + Sync, P: Ord + Clone + Send + Sync>:
PureBacking<Item<D, P>>
{
/// Update an item's priority
fn update(data: D, priority: P) -> Result<(), ()>;
/// Remove an item from the queue
fn remove(data: D) -> bool;
}

View file

@ -1,3 +1,3 @@
pub mod indexed;
pub mod item;
pub mod keyed;
pub mod pure;

View file

@ -2,11 +2,11 @@ pub mod backing;
pub mod queue;
use pyo3::prelude::*;
use queue::pure::PureQueue;
use queue::keyed::KeyedQueue;
/// Bindings for the Rust queue implementations
#[pymodule]
fn pyority_queue(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PureQueue>()?;
m.add_class::<KeyedQueue>()?;
Ok(())
}

View file

@ -6,12 +6,12 @@ use crate::backing::{
use pyo3::prelude::*;
#[pyclass]
pub struct PureQueue {
pub struct KeyedQueue {
backing: Box<dyn PureBacking<Item<Py<PyAny>, f64>>>,
}
#[pymethods]
impl PureQueue {
impl KeyedQueue {
#[new]
fn new() -> Self {
Self {

View file

@ -1 +1 @@
pub mod pure;
pub mod keyed;