semvec/pypi-packages huggingface dataset:
deque2 0.0.1
like collections.deque, but different
Keywords: deque,collections,data-structure,python

# deque 
[![PyPI version](https://img.shields.io/pypi/v/deque2?color=%2347ccbd)](https://pypi.org/project/deque2/)
[![License](https://img.shields.io/pypi/l/deque2?color=%2347ccbd)](https://opensource.org/licenses/BSD-3-Clause)
[![python](https://img.shields.io/pypi/pyversions/deque2?color=%2347ccbd)](https://pypi.org/project/deque2/)
[![status](https://img.shields.io/pypi/status/deque2?color=%2347ccbd)](https://pypi.org/project/deque2/)
[![downloads](https://img.shields.io/pypi/dm/deque2?color=%2347ccbd)](https://pypi.org/project/deque2/)

*Work-in-progress* drop-in replacement for Python's [`collection.deque`](https://docs.python.org/3/library/collections.html#collections.deque) with O(1) item access and without sacrificing performance on other metrics.

## Getting Started
The easiest way to get `deque` is to:
```
$ pip install deque
```
Alternatively, you can build it from source:
```
$ git clone https://github.com/styfenschaer/deque.git
$ cd deque
$ python setup.py install
``` 
The latter requires a C compiler compatible with your Python installation.

Once installed, it behaves like the built-in `deque` but with O(1) instead of O(n) random item access:
```python
import collections
import deque

co_deque = collections.deque(range(1_000_000))
de_deque = deque.deque(range(1_000_000))

%timeit co_deque[500_000]
%timeit de_deque[500_000]
# 76.5 µs ± 889 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
# 32.8 ns ± 0.603 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
```

## Implemented Methods
- `__init__` (only first argument)
- `append`
- `appendleft`
- `pop`
- `popleft`
- `extend`
- `extendleft`
- `clear`
- `__getitem__`
- `__setitem__`
- `__len__`
- `__repr__`
- `__str__`

## Implemented Properties
- `maxlen` (always `None`)