Elastic Hashing (Rust + Python)
A high-performance, open-addressing hash table implementation based on the 2025 paper "Optimal Bounds for Open Addressing Without Reordering".
This library is written in Rust and exposed to Python via PyO3. It achieves O(1) amortized probe complexity even at extremely high load factors (95%+), without needing to move elements after insertion (no Robin Hood or Cuckoo hashing required).
Features
- Theoretical Breakthrough: Implements the Elastic Hashing algorithm (Farach-Colton, Krapivin, Kuszmaul, 2025).
- High Load Efficiency: Maintains performance stability up to 95% load factor.
- No Reordering: Keys are never moved once inserted, making it suitable for scenarios where pointer stability is preferred.
- Double Hashing: Uses GCD-guaranteed double hashing to eliminate primary clustering and minimize variance.
- Thread Safety: Fully compatible with Python's GIL.
Installation
From Source
pip install maturin
maturin develop --release
From pypi
pip install rb-elastic-hash
Usage
import rb_elastic_hash
# Easy way: Specify how many items you want to store
# This will automatically size the table for 90% load factor (default)
table = rb_elastic_hash.ElasticTable.for_items(1_000_000)
# Want higher space efficiency? Increase the load factor
table = rb_elastic_hash.ElasticTable.for_items(1_000_000, load_factor=0.95)
# Advanced: Create with explicit capacity and delta parameter
# Delta 0.05 implies a target load factor of 95%
table = rb_elastic_hash.ElasticTable(1_000_000, delta=0.05)
# Insert items
# Returns the number of probes used for the insertion
probes = table.insert(42, "Meaning of life")
print(f"Inserted in {probes} probes.")
# Retrieve items
value = table.get(42)
print(value) # Output: "Meaning of life"
API Reference
ElasticTable.for_items(expected_items, load_factor=0.90)
Recommended for most users. Creates a table sized to store expected_items at the specified load factor.
expected_items: Number of items you plan to insertload_factor: Target load factor (default: 0.90). Higher = more space-efficient. Range: 0.5-0.98
ElasticTable(capacity, delta=0.05)
Advanced constructor. Creates a table with a specific slot capacity.
capacity: Total number of slots (not items)delta: Elasticity parameter (default: 0.05). Target load factor = 1 - delta. Range: 0.01-0.5
Benchmarks
In tests with 1,000,000 items at 95% Load Factor:
| Metric | Standard Linear Probing | Standard Double Hashing | Elastic Hashing |
|---|---|---|---|
| Average Probes | ~200 | ~20 | ~3.6 |
| Max Probes | > 5,000 | ~500 | ~320 |
Elastic Hashing achieves ~5.5x better probe efficiency than standard Double Hashing and ~50x better than Linear Probing at this load.
How It Works
Elastic Hashing divides the table into geometrically decreasing subarrays ($A_0, A_1, \dots$).
- Greedy Insert: It tries to insert into array $A_i$.
- Elastic Skip: If $A_i$ becomes too full (based on a calculated threshold f(ε)), the algorithm "skips" $A_i$ and attempts to insert into the next, smaller array $A_{i+1}$.
- Backpressure: If deeper arrays fill up, they force previous arrays to accept more elements, balancing the load perfectly across the structure.
This approach overcomes the "Coupon Collector Problem" that typically destroys performance in high-load open-addressing tables.
Reference
Based on:
Optimal Bounds for Open Addressing Without Reordering Martín Farach-Colton, Andrew Krapivin, William Kuszmaul arXiv:2501.02305v2 [cs.DS] (2025)
Metadata
Release files for rb-elastic-hash 1.0.1
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 | |
|---|---|---|---|---|
| rb_elastic_hash-1.0.1.tar.gz | 9.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rb_elastic_hash-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 239.0 kB
Release files / rb_elastic_hash-1.0.1.tar.gz
| Download URL | rb_elastic_hash-1.0.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0576aeae10cdec32fe17c52ed70cfb93db4b9533b3e60085e9a2a0ad8545fa8
|
|
BLAKE2b-256 checksum How to use checksums |
34ce936ac1214de3369f548e0d3079d44800311e77e686d94d601ae73adaa728
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.11.5
|
Release files / rb_elastic_hash-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | rb_elastic_hash-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 229.6 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e2706aca052dbec96ee3a2f3409c0da95fa4b48c73e20b402d0ec8411836af75
|
|
BLAKE2b-256 checksum How to use checksums |
0caae84d53f5ca21e6f461328b582a8718fbe1aac752b15cb44844a069b13302
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.11.5
|
Security for rb-elastic-hash 1.0.1
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.