Metadata-Version: 2.4
Name: IsraeliQueue
Version: 1.2.0
Summary: A Python implementation of Israeli Queues with comprehensive testing and type safety
Author-email: Yon Liud <ejliud@gmail.com>
Maintainer-email: Yon Liud <ejliud@gmail.com>
License: MIT License
        
        Copyright (c) 2021 Yonatan Mark Liudmirsky
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/YonLiud/Israeli-Queue
Project-URL: Documentation, https://github.com/YonLiud/Israeli-Queue#readme
Project-URL: Repository, https://github.com/YonLiud/Israeli-Queue.git
Project-URL: Bug Tracker, https://github.com/YonLiud/Israeli-Queue/issues
Project-URL: Changelog, https://github.com/YonLiud/Israeli-Queue#changelog
Project-URL: PyPI, https://pypi.org/project/IsraeliQueue/
Keywords: queue,data-structure,israeli-queue,priority-queue,algorithm,social-queuing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
Requires-Dist: hypothesis>=6.68.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
Requires-Dist: safety>=2.0.0; extra == "dev"
Requires-Dist: bandit>=1.7.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Requires-Dist: build>=0.10.0; extra == "dev"
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Dynamic: license-file

# 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.

[![PyPI](https://img.shields.io/pypi/v/IsraeliQueue)](https://pypi.org/project/IsraeliQueue/)
[![License: MIT](https://img.shields.io/github/license/YonLiud/Israeli-Queue)](LICENSE.txt)
[![Coverage](https://img.shields.io/badge/coverage-97%25-brightgreen)](tests/)

![](https://github.com/user-attachments/assets/566e3f91-dfdb-4cad-988e-3622f4535d3e)

## 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

```bash
pip install IsraeliQueue
```

## Usage

### Basic queue

```python
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:

```python
queue.put(bob, alice)  # Bob joins immediately after Alice
```

### Type-based grouping

`IsraeliQueueByType` automatically groups elements by their Python type:

```python
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

```bash
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](LICENSE.txt)
