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
Metadata
Release files for IsraeliQueue 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| israeliqueue-1.2.0.tar.gz | 19.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| israeliqueue-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.1 kB
Release files / israeliqueue-1.2.0.tar.gz
| Download URL | israeliqueue-1.2.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
155ff1b54eb7cc7bf946658ea816cdd4272632e05ac7b8049dfb3348b3880720
|
|
BLAKE2b-256 checksum How to use checksums |
339fb4d62a97294af5ba3e69672c61224a785c6e73f86f15b5417d958eaad4a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / israeliqueue-1.2.0-py3-none-any.whl
| Download URL | israeliqueue-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa9addbf54561f9eff83fcf1b9ce130460272a47b157d393a466d8cfd3714a87
|
|
BLAKE2b-256 checksum How to use checksums |
bf7bd6fb34bedb9a4ff5aef14053a53f6edb64f7994a7d1f207b9923de696d3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|