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.
|
||||
"""
|
||||
|
|
|
@ -2,11 +2,11 @@ pub mod backing;
|
|||
pub mod queue;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use queue::keyed::KeyedQueue;
|
||||
use queue::paired::PairedQueue;
|
||||
|
||||
/// Bindings for the Rust queue implementations
|
||||
#[pymodule]
|
||||
fn pyority_queue(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<KeyedQueue>()?;
|
||||
m.add_class::<PairedQueue>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub mod keyed;
|
||||
pub mod paired;
|
||||
|
|
|
@ -6,12 +6,12 @@ use crate::backing::{
|
|||
use pyo3::prelude::*;
|
||||
|
||||
#[pyclass]
|
||||
pub struct KeyedQueue {
|
||||
pub struct PairedQueue {
|
||||
backing: Box<dyn PureBacking<Item<Py<PyAny>, f64>>>,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl KeyedQueue {
|
||||
impl PairedQueue {
|
||||
#[new]
|
||||
fn new() -> Self {
|
||||
Self {
|
|
@ -2,14 +2,14 @@ from typing import Any
|
|||
|
||||
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():
|
||||
queue = KeyedQueue()
|
||||
queue = PairedQueue()
|
||||
assert len(queue) == 0
|
||||
|
||||
|
||||
|
@ -24,8 +24,8 @@ def test_empty_creation():
|
|||
{},
|
||||
{"a": 0, "b": 1, "c": 2},
|
||||
))
|
||||
def test_creation(items: KeyedQueueInitializer):
|
||||
queue = KeyedQueue()
|
||||
def test_creation(items: PairedQueueInitializer):
|
||||
queue = PairedQueue()
|
||||
assert len(queue) == len(items)
|
||||
|
||||
|
||||
|
@ -34,8 +34,8 @@ def test_creation(items: KeyedQueueInitializer):
|
|||
((0, 0),),
|
||||
((-1, -1), (3, 3)),
|
||||
))
|
||||
def test_iteration(items: KeyedQueueInitializer):
|
||||
queue = KeyedQueue(items)
|
||||
def test_iteration(items: PairedQueueInitializer):
|
||||
queue = PairedQueue(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), ("f", 6), ("h", 8), ("e", 5), ("g", 7), ("d", 4), ("b", 2), ("a", 0)),
|
||||
))
|
||||
def test_sorting(items: KeyedQueueInitializer):
|
||||
queue = KeyedQueue(items)
|
||||
def test_sorting(items: PairedQueueInitializer):
|
||||
queue = PairedQueue(items)
|
||||
in_order = list(queue)
|
||||
assert in_order == sorted(in_order)
|
||||
|
||||
|
||||
def test_insertion():
|
||||
queue = KeyedQueue({"a": 1, "b": 2, "c": 3})
|
||||
queue = PairedQueue({"a": 1, "b": 2, "c": 3})
|
||||
queue["d"] = 4
|
||||
queue["e"] = 5
|
||||
assert list(queue) == ["a", "b", "c", "d", "e"]
|
||||
|
||||
|
||||
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() == "b"
|
||||
assert queue.pop() == "c"
|
||||
|
@ -67,26 +67,26 @@ def test_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 list(queue) == ["b", "c"]
|
||||
|
||||
|
||||
def test_empty_removal():
|
||||
queue = KeyedQueue()
|
||||
queue = PairedQueue()
|
||||
with pytest.raises(IndexError):
|
||||
queue.pop()
|
||||
|
||||
|
||||
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"] = 3
|
||||
assert list(queue) == ["a", "a", "b", "a", "b"]
|
||||
|
||||
|
||||
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 = []
|
||||
for char in queue:
|
||||
results.append(char)
|
Loading…
Add table
Add a link
Reference in a new issue