Skip to main content

A Rust-based implementation of Elastic Hashing (arXiv:2501.02305v2)

Project description

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

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 insert
  • load_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$).

  1. Greedy Insert: It tries to insert into array $A_i$.
  2. Elastic Skip: If $A_i$ becomes too full (based on a calculated threshold $f(\epsilon)$), the algorithm "skips" $A_i$ and attempts to insert into the next, smaller array $A_{i+1}$.
  3. 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rb_elastic_hash-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

rb_elastic_hash-1.0.0-cp313-cp313-manylinux_2_34_x86_64.whl (229.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

File details

Details for the file rb_elastic_hash-1.0.0.tar.gz.

File metadata

  • Download URL: rb_elastic_hash-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for rb_elastic_hash-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9fbbfeac286e18de039cb86d4c2757210a8c1bb10407a54ace30268e2089ed5b
MD5 26dc8839740791be39e1b28030e0c359
BLAKE2b-256 63ad4bb266c7eb35be7eea9a7cd80c755236aa369023e21bc0bc3c2e71f98d71

See more details on using hashes here.

File details

Details for the file rb_elastic_hash-1.0.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rb_elastic_hash-1.0.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 331d9c2e2700d837bf2691e83e2afee6a0b055c98dc7c995fafa283ea53e56e6
MD5 5e83dda6c50d65de81c25a59a7e76198
BLAKE2b-256 ab3fcacb5063f96252d6c8abfe6f1d445196a4a7fcf1aa0a8d7a92e878f45863

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page