larzstruct
Data structures the standard library leaves out. Pure Python, zero deps.
A probabilistic set (Bloom filter), a prefix tree (Trie), a union-find (disjoint set), and a fixed-size ring buffer — the ones you reach for often enough to want, without re-implementing them each time.
from larzstruct import BloomFilter, Trie, DisjointSet, RingBuffer
bf = BloomFilter(capacity=10000, error_rate=0.01)
bf.add("alice"); "alice" in bf # True (never a false negative)
t = Trie(); t.insert("apple"); t.insert("app")
t.starts_with("ap"); t.keys("ap") # ['app', 'apple']
ds = DisjointSet(); ds.union(1, 2); ds.connected(1, 2) # True
rb = RingBuffer(3); rb.extend([1, 2, 3, 4]); rb.to_list() # [2, 3, 4]
What's inside
- BloomFilter — space-efficient set membership; computes the optimal bit-array
size and hash count from your
capacity+ targeterror_rate. No false negatives; false positives stay under the target. Great for "have I seen this?" at scale. - Trie —
insert,in,starts_with, andkeys(prefix)for fast prefix queries and autocomplete. - DisjointSet (union-find) —
union/find/connected/groupswith path compression and union by rank. Connectivity, clustering, cycle detection. - RingBuffer — fixed capacity, appends past capacity overwrite the oldest;
iterates oldest-first, with
latest(n),is_full(),to_list().
Zero dependencies — pure standard library.
Install
pip install larzstruct
Tests
python -m unittest discover -s tests -v # 17 tests
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT © larz-scripter
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 larzstruct-0.1.0.tar.gz.
File metadata
- Download URL: larzstruct-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c0cd63e0e5af30ea674ca2f5827e70838cc27b7d29c7b5e49b4508eed9e8f1
|
|
| MD5 |
595bede7b3a3d4d7e0bce7f107f6f8fa
|
|
| BLAKE2b-256 |
5fe9abdf78a4ed83b7fbfc10ddc7cf3ae35f5d1d993562564a7e09d7ebc53f79
|
File details
Details for the file larzstruct-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzstruct-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
376d7adf1c6f0103661fd5222aaf724d2513a75d0451e4c39d0964319b59d351
|
|
| MD5 |
147692c356c92cf0ac143a40ca8e727b
|
|
| BLAKE2b-256 |
9100a173acee6e36ca43a1d48252afd828db79b8a1f7fe48bbd3c07f4d5a0944
|