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.2.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.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for optopenhash-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9e680bc727b96f144ade13bb3ac674267e244e045d7f44d8c3195c38b3aa7bc
MD5 a02483709787e403b8c9987075230548
BLAKE2b-256 66234a9fe1c9b986fb999f6830ab9e3274509ed5c0da40bf3a9017a85e3152f5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for optopenhash-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 196a5389667a8d0029c66ba75f786c9b44d67180189914219449b57ddd47bc5d
MD5 795595ab37078076396adc15bc4ac66e
BLAKE2b-256 3f8520fbb8e921cc8bbd7e71e533209d24f07d351a960130db6a6d1bca4aa976

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