Skip to main content

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 + target error_rate. No false negatives; false positives stay under the target. Great for "have I seen this?" at scale.
  • Trieinsert, in, starts_with, and keys(prefix) for fast prefix queries and autocomplete.
  • DisjointSet (union-find) — union/find/connected/groups with 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

larzstruct-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

larzstruct-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for larzstruct-0.1.0.tar.gz
Algorithm Hash digest
SHA256 03c0cd63e0e5af30ea674ca2f5827e70838cc27b7d29c7b5e49b4508eed9e8f1
MD5 595bede7b3a3d4d7e0bce7f107f6f8fa
BLAKE2b-256 5fe9abdf78a4ed83b7fbfc10ddc7cf3ae35f5d1d993562564a7e09d7ebc53f79

See more details on using hashes here.

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

Hashes for larzstruct-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 376d7adf1c6f0103661fd5222aaf724d2513a75d0451e4c39d0964319b59d351
MD5 147692c356c92cf0ac143a40ca8e727b
BLAKE2b-256 9100a173acee6e36ca43a1d48252afd828db79b8a1f7fe48bbd3c07f4d5a0944

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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