Rename KeyedQueue to PairedQueue
This commit is contained in:
parent
17b544f8bc
commit
6e91aef421
5 changed files with 21 additions and 21 deletions
|
@ -47,7 +47,7 @@ class PureQueue[Data: Comparable](Queue[Data]):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class KeyedQueue[Data, Priority: Comparable](Queue[Data]):
|
class PairedQueue[Data, Priority: Comparable](Queue[Data]):
|
||||||
"""
|
"""
|
||||||
A min-queue that allows arbitrary data associated with some priority, allowing duplicates of both data and priority.
|
A min-queue that allows arbitrary data associated with some priority, allowing duplicates of both data and priority.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,11 +2,11 @@ pub mod backing;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use queue::keyed::KeyedQueue;
|
use queue::paired::PairedQueue;
|
||||||
|
|
||||||
/// Bindings for the Rust queue implementations
|
/// Bindings for the Rust queue implementations
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn pyority_queue(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
fn pyority_queue(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||||
m.add_class::<KeyedQueue>()?;
|
m.add_class::<PairedQueue>()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
pub mod keyed;
|
pub mod paired;
|
||||||
|
|
|
@ -6,12 +6,12 @@ use crate::backing::{
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct KeyedQueue {
|
pub struct PairedQueue {
|
||||||
backing: Box<dyn PureBacking<Item<Py<PyAny>, f64>>>,
|
backing: Box<dyn PureBacking<Item<Py<PyAny>, f64>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl KeyedQueue {
|
impl PairedQueue {
|
||||||
#[new]
|
#[new]
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
|
@ -2,14 +2,14 @@ from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyority_queue import Comparable, KeyedQueue
|
from pyority_queue import Comparable, PairedQueue
|
||||||
|
|
||||||
|
|
||||||
type KeyedQueueInitializer = dict[Any, Comparable] | list[tuple[Any, Comparable]] | tuple[tuple[Any, Comparable], ...]
|
type PairedQueueInitializer = dict[Any, Comparable] | list[tuple[Any, Comparable]] | tuple[tuple[Any, Comparable], ...]
|
||||||
|
|
||||||
|
|
||||||
def test_empty_creation():
|
def test_empty_creation():
|
||||||
queue = KeyedQueue()
|
queue = PairedQueue()
|
||||||
assert len(queue) == 0
|
assert len(queue) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ def test_empty_creation():
|
||||||
{},
|
{},
|
||||||
{"a": 0, "b": 1, "c": 2},
|
{"a": 0, "b": 1, "c": 2},
|
||||||
))
|
))
|
||||||
def test_creation(items: KeyedQueueInitializer):
|
def test_creation(items: PairedQueueInitializer):
|
||||||
queue = KeyedQueue()
|
queue = PairedQueue()
|
||||||
assert len(queue) == len(items)
|
assert len(queue) == len(items)
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ def test_creation(items: KeyedQueueInitializer):
|
||||||
((0, 0),),
|
((0, 0),),
|
||||||
((-1, -1), (3, 3)),
|
((-1, -1), (3, 3)),
|
||||||
))
|
))
|
||||||
def test_iteration(items: KeyedQueueInitializer):
|
def test_iteration(items: PairedQueueInitializer):
|
||||||
queue = KeyedQueue(items)
|
queue = PairedQueue(items)
|
||||||
assert len(list(queue)) == len(items)
|
assert len(list(queue)) == len(items)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,21 +45,21 @@ def test_iteration(items: KeyedQueueInitializer):
|
||||||
(("c", 3.0), ("b", 2.0), ("a", 1.0)),
|
(("c", 3.0), ("b", 2.0), ("a", 1.0)),
|
||||||
(("c", 3), ("f", 6), ("h", 8), ("e", 5), ("g", 7), ("d", 4), ("b", 2), ("a", 0)),
|
(("c", 3), ("f", 6), ("h", 8), ("e", 5), ("g", 7), ("d", 4), ("b", 2), ("a", 0)),
|
||||||
))
|
))
|
||||||
def test_sorting(items: KeyedQueueInitializer):
|
def test_sorting(items: PairedQueueInitializer):
|
||||||
queue = KeyedQueue(items)
|
queue = PairedQueue(items)
|
||||||
in_order = list(queue)
|
in_order = list(queue)
|
||||||
assert in_order == sorted(in_order)
|
assert in_order == sorted(in_order)
|
||||||
|
|
||||||
|
|
||||||
def test_insertion():
|
def test_insertion():
|
||||||
queue = KeyedQueue({"a": 1, "b": 2, "c": 3})
|
queue = PairedQueue({"a": 1, "b": 2, "c": 3})
|
||||||
queue["d"] = 4
|
queue["d"] = 4
|
||||||
queue["e"] = 5
|
queue["e"] = 5
|
||||||
assert list(queue) == ["a", "b", "c", "d", "e"]
|
assert list(queue) == ["a", "b", "c", "d", "e"]
|
||||||
|
|
||||||
|
|
||||||
def test_removal():
|
def test_removal():
|
||||||
queue = KeyedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
queue = PairedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
||||||
assert queue.pop() == "a"
|
assert queue.pop() == "a"
|
||||||
assert queue.pop() == "b"
|
assert queue.pop() == "b"
|
||||||
assert queue.pop() == "c"
|
assert queue.pop() == "c"
|
||||||
|
@ -67,26 +67,26 @@ def test_removal():
|
||||||
|
|
||||||
|
|
||||||
def test_mixed_removal():
|
def test_mixed_removal():
|
||||||
queue = KeyedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
queue = PairedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
||||||
assert queue.pop() == "a"
|
assert queue.pop() == "a"
|
||||||
assert list(queue) == ["b", "c"]
|
assert list(queue) == ["b", "c"]
|
||||||
|
|
||||||
|
|
||||||
def test_empty_removal():
|
def test_empty_removal():
|
||||||
queue = KeyedQueue()
|
queue = PairedQueue()
|
||||||
with pytest.raises(IndexError):
|
with pytest.raises(IndexError):
|
||||||
queue.pop()
|
queue.pop()
|
||||||
|
|
||||||
|
|
||||||
def test_duplicates():
|
def test_duplicates():
|
||||||
queue = KeyedQueue[str, int]((("a", 0), ("a", 0), ("a", 2)))
|
queue = PairedQueue[str, int]((("a", 0), ("a", 0), ("a", 2)))
|
||||||
queue["b"] = 1
|
queue["b"] = 1
|
||||||
queue["b"] = 3
|
queue["b"] = 3
|
||||||
assert list(queue) == ["a", "a", "b", "a", "b"]
|
assert list(queue) == ["a", "a", "b", "a", "b"]
|
||||||
|
|
||||||
|
|
||||||
def test_mixed_iteration():
|
def test_mixed_iteration():
|
||||||
queue = KeyedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
queue = PairedQueue[str, int]({"a": 1, "b": 2, "c": 3})
|
||||||
results = []
|
results = []
|
||||||
for char in queue:
|
for char in queue:
|
||||||
results.append(char)
|
results.append(char)
|
Loading…
Add table
Add a link
Reference in a new issue