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_back— O(1)pop_front/pop_back— O(1)hash()of the current contents — O(1)- equality between two
HashDequeinstances — 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e71cebb3e8772cef3f549ab0117d788d8e59216b2597d1b931f36ecbf0aa29e3
|
|
| MD5 |
41b073e5ccdd2d28cc11bdcdc8ec3acb
|
|
| BLAKE2b-256 |
8db3025686ad29ffc28d9d19613cfdc089cfa881b6f991ae6d254c69a57e54d4
|
Provenance
The following attestation bundles were made for hashdeque-0.0.2.tar.gz:
Publisher:
publish.yml on dheeraj-6904/RollingHashDeque
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hashdeque-0.0.2.tar.gz -
Subject digest:
e71cebb3e8772cef3f549ab0117d788d8e59216b2597d1b931f36ecbf0aa29e3 - Sigstore transparency entry: 2138579677
- Sigstore integration time:
-
Permalink:
dheeraj-6904/RollingHashDeque@2338f75db60d81e3c72ea78fd3d30f6aa1f4de51 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/dheeraj-6904
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2338f75db60d81e3c72ea78fd3d30f6aa1f4de51 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3d4ab0ba98ec8e344d2a91c9e3958ec5ee01b5a2df3962648972baaa4bb526a
|
|
| MD5 |
6f66319bbd12c120ee86ff6345f70bd1
|
|
| BLAKE2b-256 |
c561283c28c935a440c5ddc1b02c8b27212b497bf5389506b923c3b4a97871aa
|
Provenance
The following attestation bundles were made for hashdeque-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on dheeraj-6904/RollingHashDeque
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hashdeque-0.0.2-py3-none-any.whl -
Subject digest:
b3d4ab0ba98ec8e344d2a91c9e3958ec5ee01b5a2df3962648972baaa4bb526a - Sigstore transparency entry: 2138579686
- Sigstore integration time:
-
Permalink:
dheeraj-6904/RollingHashDeque@2338f75db60d81e3c72ea78fd3d30f6aa1f4de51 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/dheeraj-6904
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2338f75db60d81e3c72ea78fd3d30f6aa1f4de51 -
Trigger Event:
push
-
Statement type: