Skip to content

Queue Utilities

The rite.collections.queue subpackage provides queue abstractions, including priority queues, circular queues, and convenient wrappers around deque-based queues.

Queue Collections Module

Provides specialized queue implementations.

Classes:

  • PriorityQueue: Priority-based queue
  • DequeWrapper: Enhanced deque wrapper
  • CircularQueue: Circular queue implementation

Classes

CircularQueue(capacity: int)

CircularQueue Class

A fixed-size circular queue (FIFO).

Initialize a circular queue.


capacity: Maximum capacity of the queue.

Functions

clear() -> None

Clear all items from queue.

dequeue() -> Any

Remove and return item from front of queue.


Any: The front item.
enqueue(item: Any) -> bool

Add an item to the rear of the queue.


item: Item to add.
is_empty() -> bool

Check if queue is empty.

is_full() -> bool

Check if queue is full.

peek() -> Any

Return front item without removing it.


Any: The front item.

DequeWrapper(max_size: int | None = None)

DequeWrapper Class

A wrapper around collections.deque with additional utilities.

Initialize a deque wrapper.


max_size: Maximum length of the deque.

Functions

clear() -> None

Remove all items.

is_empty() -> bool

Check if deque is empty.

peek_left() -> Any

Return item at left end without removing.

peek_right() -> Any

Return item at right end without removing.

pop_left() -> Any

Remove and return item from left end.

pop_right() -> Any

Remove and return item from right end.

push_left(item: Any) -> None

Add item to the left end.

push_right(item: Any) -> None

Add item to the right end.

rotate(n: int = 1) -> None

Rotate deque n steps to the right.


n: Number of steps to rotate (negative for left rotation).
to_list() -> list[Any]

Convert to list.

PriorityQueue()

PriorityQueue Class

A priority queue where items with lower priority values are dequeued first.

Initialize an empty priority queue.

Functions

clear() -> None

Remove all items from the queue.

is_empty() -> bool

Check if queue is empty.


bool: True if queue is empty.
peek() -> Any

Return the highest priority item without removing it.


Any: The highest priority item.
pop() -> Any

Remove and return the highest priority item.


Any: The highest priority item.
push(item: Any, priority: float = 0.0) -> None

Add an item with a given priority.


item: The item to add.
priority: Priority value (lower = higher priority).

Modules

circular_queue

Circular Queue

A circular queue with fixed capacity.

Classes

CircularQueue(capacity: int)
CircularQueue Class

A fixed-size circular queue (FIFO).

Initialize a circular queue.


capacity: Maximum capacity of the queue.
Functions
clear() -> None

Clear all items from queue.

dequeue() -> Any

Remove and return item from front of queue.


Any: The front item.
enqueue(item: Any) -> bool

Add an item to the rear of the queue.


item: Item to add.
is_empty() -> bool

Check if queue is empty.

is_full() -> bool

Check if queue is full.

peek() -> Any

Return front item without removing it.


Any: The front item.

deque_wrapper

Deque Wrapper

Enhanced deque wrapper with additional functionality.

Classes

DequeWrapper(max_size: int | None = None)
DequeWrapper Class

A wrapper around collections.deque with additional utilities.

Initialize a deque wrapper.


max_size: Maximum length of the deque.
Functions
clear() -> None

Remove all items.

is_empty() -> bool

Check if deque is empty.

peek_left() -> Any

Return item at left end without removing.

peek_right() -> Any

Return item at right end without removing.

pop_left() -> Any

Remove and return item from left end.

pop_right() -> Any

Remove and return item from right end.

push_left(item: Any) -> None

Add item to the left end.

push_right(item: Any) -> None

Add item to the right end.

rotate(n: int = 1) -> None

Rotate deque n steps to the right.


n: Number of steps to rotate (negative for left rotation).
to_list() -> list[Any]

Convert to list.

priority_queue

Priority Queue

A priority queue implementation using heapq.

Classes

PriorityQueue()
PriorityQueue Class

A priority queue where items with lower priority values are dequeued first.

Initialize an empty priority queue.

Functions
clear() -> None

Remove all items from the queue.

is_empty() -> bool

Check if queue is empty.


bool: True if queue is empty.
peek() -> Any

Return the highest priority item without removing it.


Any: The highest priority item.
pop() -> Any

Remove and return the highest priority item.


Any: The highest priority item.
push(item: Any, priority: float = 0.0) -> None

Add an item with a given priority.


item: The item to add.
priority: Priority value (lower = higher priority).

options: show_root_heading: true show_source: false heading_level: 2