https://github.com/jconleyscales/two-dimensional-q
Fixed-capacity circular queue backed by a 2D list with wrap-around indexing (Python).
https://github.com/jconleyscales/two-dimensional-q
circular-buffer data-structures python queue
Last synced: 3 months ago
JSON representation
Fixed-capacity circular queue backed by a 2D list with wrap-around indexing (Python).
- Host: GitHub
- URL: https://github.com/jconleyscales/two-dimensional-q
- Owner: jconleyscales
- Created: 2025-12-22T00:30:45.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-12-22T01:25:42.000Z (3 months ago)
- Last Synced: 2025-12-23T11:47:40.794Z (3 months ago)
- Topics: circular-buffer, data-structures, python, queue
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TwoDimensionalQ (2D Circular Queue) — Python
A fixed-capacity queue backed by a **2D list** that uses **wrap-around indexing** (circular buffer behavior) to avoid shifting elements.
## Features
- Fixed capacity with usage tracking
- Row-major wrap-around indexing across a 2D backing store
- Core operations:
- `enqueue(item)` → `True` if added, `False` if full
- `dequeue()` → removed item, or `None` if empty
- `peek()` → front item without removing it, or `None` if empty
- `list_queue()` → items in queue order
## How to Run
1. Make sure you have Python 3 installed.
2. Run the file:
```bash```
python two_dimensional_q.py
## Example Usage
```python
from two_dimensional_q import TwoDimensionalQ
q = TwoDimensionalQ(2) # capacity = 4
q.enqueue("A")
q.enqueue("B")
print(q.peek()) # A
print(q.dequeue()) # A
print(q.list_queue()) # ['B']