Skip to main content

A Python package implementing improved open‐addressing hash tables based on the paper "Optimal Bounds for Open Addressing Without Reordering".

Project description

OptOpenHash

This package implements two new open‐addressing hash tables inspired by the research paper

Optimal Bounds for Open Addressing Without Reordering
Martín Farach‐Colton, Andrew Krapivin, William Kuszmaul
Link

In this implementation I provide:

  • ElasticHashTable – an “elastic hashing” table that partitions the table into levels (arrays) of geometrically decreasing size and uses a non‐greedy (i.e. “elastic”) insertion strategy.
  • FunnelHashTable – a greedy open‐addressing table that partitions the table into multiple “funnel” levels (with each level subdivided into buckets) and falls back on a special “overflow” array.

Both tables support insert(key, value) and search(key) operations (as well as Python’s “in” and len()).

Installation

Install via pip:

pip install optopenhash

Clone the repository and install via pip:

bash
git clone https://github.com/sternma/optopenhash.git
cd optopenhash
pip install .

Usage

from optopenhash import ElasticHashTable, FunnelHashTable

# Create a table with capacity 1000 and delta = 0.1 (so up to 900 insertions)
etable = ElasticHashTable(capacity=1000, delta=0.1)
fhtable = FunnelHashTable(capacity=1000, delta=0.1)

# Insert some key-value pairs
for i in range(800):
    etable.insert(f"key{i}", f"value{i}")
    fhtable.insert(f"key{i}", f"value{i}")

# Search for a key
print(etable.search("key123"))
print(fhtable.search("key123"))

Testing

A basic test suite is provided in the tests directory. To run the tests use:

pytest tests

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

optopenhash-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

optopenhash-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file optopenhash-0.1.0.tar.gz.

File metadata

  • Download URL: optopenhash-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for optopenhash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 28d9dc6b9687bf4d5866117183a4a8ac4869f8b5b5a59aa23d67c3b092b6cdca
MD5 32e16b5185dc337c1f5fa08549c37bce
BLAKE2b-256 86a53f95ce7585891a173f461acfb66f0c8632283301d50883bab19ff1c8add7

See more details on using hashes here.

File details

Details for the file optopenhash-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: optopenhash-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for optopenhash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a1327a87ccd25ffe6b4f6aa6c708f7c607cee9c33442f064d4f8054d3e534b7
MD5 6d422e0b7b408ac776a62efffe6317bc
BLAKE2b-256 09819123bd375735d4233f8abdba93661d5e9e32c78a4132a7e2b258f06a14d9

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