Skip to main content

like collections.deque, but different

Project description

deque-one

PyPI version License python status downloads

Work-in-progress drop-in replacement for Python's collection.deque with O(1) item access and without sacrificing performance on other metrics.

Getting Started

The easiest way to get deque-one is to:

$ pip install deque-one

Alternatively, you can build it from source:

$ git clone https://github.com/styfenschaer/deque-one.git
$ cd deque-one
$ 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:

import collections
import deque_one

col_deque = collections.deque(range(1_000_000))
one_deque = deque_one.deque(range(1_000_000))

%timeit col_deque[0]
%timeit one_deque[0]
# 33.6 ns ± 0.422 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
# 33.3 ns ± 1.08 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

%timeit col_deque[500_000]
%timeit one_deque[500_000]
# 89.3 µs ± 1.93 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
# 38.2 ns ± 1.45 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)

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

deque-one-0.0.1.tar.gz (16.6 kB view hashes)

Uploaded Source

Built Distributions

deque_one-0.0.1-cp312-cp312-win_amd64.whl (15.9 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

deque_one-0.0.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (37.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

deque_one-0.0.1-cp312-cp312-macosx_11_0_arm64.whl (13.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

deque_one-0.0.1-cp312-cp312-macosx_10_9_x86_64.whl (12.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

deque_one-0.0.1-cp311-cp311-win_amd64.whl (15.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

deque_one-0.0.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (36.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

deque_one-0.0.1-cp311-cp311-macosx_11_0_arm64.whl (12.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

deque_one-0.0.1-cp311-cp311-macosx_10_9_x86_64.whl (12.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

deque_one-0.0.1-cp310-cp310-win_amd64.whl (15.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

deque_one-0.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

deque_one-0.0.1-cp310-cp310-macosx_11_0_arm64.whl (12.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

deque_one-0.0.1-cp310-cp310-macosx_10_9_x86_64.whl (12.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page