This release is a pre-release and may not be stable for production use.
uniqdeque
A hybrid data structure combining a deque (double-ended queue) and a set (unique elements).
Features
- Double-ended operations:
push_front(elem): Insert at front (if not a duplicate) in O(1) time.push_back(elem): Append at back (if not a duplicate) in O(1) time.pop_front()/pop_back(): Remove from either end in O(1) time.
- Uniqueness: Automatically rejects duplicates on insertion.
- Order-preserving: Maintains insertion order.
- Fast membership testing:
elem in dqchecks in O(1) time.
Use Cases
- LRU/LFU Caches: Evict least-recently-used items while avoiding duplicates.
- Message Queues: Deduplicate messages while supporting queue/dequeue at both ends.
- Sliding Window Analytics: Track unique elements in a time window (e.g., "unique visitors in the last 5 minutes").
Installation
pip install uniqdeque
Usage Example
from uniqdeque import uniqdeque
dq = uniqdeque([1, 2, 3]) # Initialize with elements
dq.push_front(0) # -> [0, 1, 2, 3]
dq.push_back(3) # No effect (duplicate)
dq.pop_back() # Returns 3, dq -> [0, 1, 2]
Performance
| Operation | Time Complexity | Notes |
|---|---|---|
push_* |
O(1) | Rejects duplicates in O(1). |
pop_* |
O(1) | Raises KeyError if empty. |
discard(elem) |
O(1) | Safe removal if present. |
len(dq) |
O(1) |
API Reference
Core Methods
push_front(elem: T) -> NoneAdd to front if not a duplicate.push_back(elem: T) -> NoneAppend to back if not a duplicate.pop_front() -> TRemove and return front element. RaisesKeyErrorif empty.pop_back() -> TRemove and return back element. RaisesKeyErrorif empty.
Utilities
discard(elem: T) -> NoneRemove element if present (no-op otherwise).clear() -> NoneRemove all elements.copy() -> uniqdeque[T]Return a shallow copy.
Design Choices
- Backed by: An
OrderedDict(forO(1)lookups andO(1)head/tail ops). - Alternatives: Tree-based map (e.g., C++'s
std::map) for ordered elements (O(log n)lookups).
Contributing
Contributions are welcome! Please submit pull requests or open issues on GitHub.
License
MIT
Metadata
Release files for uniqdeque 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uniqdeque-0.1.0a0.tar.gz | 3.9 kB | Without provenance | Details for uniqdeque-0.1.0a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uniqdeque-0.1.0a0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for uniqdeque-0.1.0a0-py2.py3-none-any.whl |
Total release size: 8.0 kB
Release files / uniqdeque-0.1.0a0.tar.gz
| Download URL | uniqdeque-0.1.0a0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1eb3345cb45d7b16f11cfa707005313770ec9df869d93d0552b51f563c2142cb
|
|
BLAKE2b-256 checksum How to use checksums |
cf8609bfb5ff43fe033116a5af6f0c936ac4b4f51a12b6e9271c089655a294e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / uniqdeque-0.1.0a0-py2.py3-none-any.whl
| Download URL | uniqdeque-0.1.0a0-py2.py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b35707fa640a8ee0ecebfa4189c508dcbfbecbf10b337e250959adc306b4d35c
|
|
BLAKE2b-256 checksum How to use checksums |
50f242f89daf1adc482d147a1fc6aa68098b6462011bbcdb8c23776d509d3421
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for uniqdeque 0.1.0a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.