Skip to main content

Implementation of the Jump Consistent Hash algorithm

Project description

Python implementation of the jump consistent hash algorithm by John Lamping and Eric Veach[1]. Requires Python 2.6-2.7 or 3.2+.

Usage

>>> import jump
>>> jump.hash(256, 1024)
520

Or if you want to use the C++ extension:

>>> jump.fasthash(256, 1024)
520

If you want to use a str as a key instead of an int, you can pass it through a hash function to compute a real key. Here’s a couple of examples using Python 3:

>>> import hashlib
>>> int(hashlib.md5(b'127.0.0.1').hexdigest(), 16)
325870950296970981340734819828239218902

>>> int(hashlib.sha1(b"127.0.0.1").hexdigest(), 16)
431133456357828263809343936597625557575256328153

>>> import binascii
>>> binascii.crc32(b'127.0.0.1') & 0xffffffff
3619153832

>>> abs(hash('127.0.0.1'))
7536019783825143230

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

jump_consistent_hash-2.0.2.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distributions

jump_consistent_hash-2.0.2-cp35-cp35m-macosx_10_11_x86_64.whl (6.4 kB view hashes)

Uploaded CPython 3.5m macOS 10.11+ x86-64

jump_consistent_hash-2.0.2-cp27-none-macosx_10_11_intel.whl (7.3 kB view hashes)

Uploaded CPython 2.7 macOS 10.11+ intel

Supported by

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