A Python implementation of Israeli Queues with comprehensive testing and type safety
Project description
Israeli Queue
A Python implementation of the Israeli Queue, a priority queue variant where elements join behind the last member of their group rather than at the back of the line.
How it works
In a standard queue, new elements always go to the back. In an Israeli Queue, an element's position depends on whether its group is already represented in the queue. If it is, the element joins immediately after the last member of its group. If not, it goes to the back.
This models real-world queuing behavior where people join their friends already in line rather than starting a new position at the back.
Installation
pip install IsraeliQueue
Usage
Basic queue
from IsraeliQueue import Item, IsraeliQueue
queue = IsraeliQueue()
alice = Item("Alice", group=1)
charlie = Item("Charlie", group=2)
bob = Item("Bob", group=1)
queue.enqueue(alice) # [Alice]
queue.enqueue(charlie) # [Alice, Charlie]
queue.enqueue(bob) # [Alice, Bob, Charlie] — Bob joins his group, not the back
print(queue) # [Alice, Bob, Charlie]
Explicit placement
Use put() to place an item directly after a specific friend:
queue.put(bob, alice) # Bob joins immediately after Alice
Type-based grouping
IsraeliQueueByType automatically groups elements by their Python type:
from IsraeliQueue import IsraeliQueueByType
queue = IsraeliQueueByType()
queue.enqueue("hello")
queue.enqueue(42)
queue.enqueue("world")
queue.enqueue(99)
print(queue) # [["hello", "world"], [42, 99]]
API
| Method | Description | Complexity |
|---|---|---|
enqueue(item) |
Add item; joins group if present, else appends | O(n) |
put(item, friend) |
Place item directly after friend |
O(n) |
dequeue() |
Remove and return front item | O(1) |
peek() |
Return front item without removing | O(1) |
size() |
Number of items in queue | O(1) |
is_empty() |
True if queue has no items | O(1) |
get_groups() |
List of all group IDs currently in queue | O(n) |
items_in_group(group) |
All items belonging to a group | O(n) |
Testing
pytest --cov=IsraeliQueue --cov-report=term-missing
97% coverage across 38 tests covering edge cases, error conditions, and performance.
Contributing
Issues and pull requests are welcome. For significant changes, open an issue first.
License
MIT — see LICENSE.txt
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file israeliqueue-1.2.0.tar.gz.
File metadata
- Download URL: israeliqueue-1.2.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
155ff1b54eb7cc7bf946658ea816cdd4272632e05ac7b8049dfb3348b3880720
|
|
| MD5 |
8f5a4212ba63d1bca8223110092de8f6
|
|
| BLAKE2b-256 |
339fb4d62a97294af5ba3e69672c61224a785c6e73f86f15b5417d958eaad4a3
|
File details
Details for the file israeliqueue-1.2.0-py3-none-any.whl.
File metadata
- Download URL: israeliqueue-1.2.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa9addbf54561f9eff83fcf1b9ce130460272a47b157d393a466d8cfd3714a87
|
|
| MD5 |
50aa8dc7b664a7a3f1c1ed9911d108fa
|
|
| BLAKE2b-256 |
bf7bd6fb34bedb9a4ff5aef14053a53f6edb64f7994a7d1f207b9923de696d3e
|