Skip to main content
Pre-release

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 dq checks in O(1) time.

Use Cases

  1. LRU/LFU Caches: Evict least-recently-used items while avoiding duplicates.
  2. Message Queues: Deduplicate messages while supporting queue/dequeue at both ends.
  3. 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) -> None Add to front if not a duplicate.
  • push_back(elem: T) -> None Append to back if not a duplicate.
  • pop_front() -> T Remove and return front element. Raises KeyError if empty.
  • pop_back() -> T Remove and return back element. Raises KeyError if empty.

Utilities

  • discard(elem: T) -> None Remove element if present (no-op otherwise).
  • clear() -> None Remove all elements.
  • copy() -> uniqdeque[T] Return a shallow copy.

Design Choices

  • Backed by: An OrderedDict (for O(1) lookups and O(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

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)

Source distribution for uniqdeque 0.1.0a0
File Size Uploaded
uniqdeque-0.1.0a0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uniqdeque 0.1.0a0
File Interpreter ABI Platform
uniqdeque-0.1.0a0-py2.py3-none-any.whl Python 3, Python 2 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.0a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page