Skip to main content

A string/bytes deque with an O(1) rolling hash and O(1) equality between instances.

Project description

hashdeque

A deque of characters (any Unicode symbol) that maintains a rolling hash of its contents. Powers of the base are precomputed, so the hash of the current sequence is available in O(1) after each push/pop instead of rehashing everything.

  • push_front / push_backO(1)
  • pop_front / pop_backO(1)
  • hash() of the current contents — O(1)
  • equality between two HashDeque instances — O(1) (compares rolling hashes)

Useful for substring/window matching (Rabin–Karp style), deduplication over a sliding window, and content-defined chunking.

Install

pip install hashdeque

Development setup:

uv venv
uv pip install -e ".[dev]"

Usage

from hashdeque import HashDeque

d = HashDeque()
for ch in "hello":
    d.push_back(ch)
print(d.hash())     # rolling-hash fingerprint of "hello"
d.pop_front()       # drop 'h'
print(d.hash())     # fingerprint of "ello", computed in O(1)

other = HashDeque("ello")
print(d == other)   # True, O(1) comparison

d.verify = True     # opt in to exact verification on a hash match

Test

pytest

Layout

hashdeque/
├── pyproject.toml
├── repo_structure.yaml         # enforced by the repo-structure pre-commit hook
├── .pre-commit-config.yaml
├── .github/workflows/publish.yml
├── src/hashdeque/
│   ├── __init__.py             # public API
│   ├── base.py                 # BaseHashDeque (ABC) — the contract
│   ├── params.py               # HashParams — bases/moduli/inverses
│   ├── deque.py                # HashDeque — polynomial double-hash implementation
│   └── py.typed
└── tests/
    ├── test_base.py
    ├── test_params.py
    └── test_hashdeque.py

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

hashdeque-0.0.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hashdeque-0.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file hashdeque-0.0.2.tar.gz.

File metadata

  • Download URL: hashdeque-0.0.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hashdeque-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e71cebb3e8772cef3f549ab0117d788d8e59216b2597d1b931f36ecbf0aa29e3
MD5 41b073e5ccdd2d28cc11bdcdc8ec3acb
BLAKE2b-256 8db3025686ad29ffc28d9d19613cfdc089cfa881b6f991ae6d254c69a57e54d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for hashdeque-0.0.2.tar.gz:

Publisher: publish.yml on dheeraj-6904/RollingHashDeque

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hashdeque-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hashdeque-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hashdeque-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3d4ab0ba98ec8e344d2a91c9e3958ec5ee01b5a2df3962648972baaa4bb526a
MD5 6f66319bbd12c120ee86ff6345f70bd1
BLAKE2b-256 c561283c28c935a440c5ddc1b02c8b27212b497bf5389506b923c3b4a97871aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for hashdeque-0.0.2-py3-none-any.whl:

Publisher: publish.yml on dheeraj-6904/RollingHashDeque

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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