Implementation of the Jump Consistent Hash algorithm
Project description
Jump Consistent Hash
Python implementation of the jump consistent hash algorithm by John Lamping and Eric Veach[1]. Tested on Python 2.6, 2.7 and 3.4+.
Install
To install Jump Consistent Hash, simply run this simple command in your terminal of choice:
$ pip install jump-consistent-hash
Unless running PyPy the installation will try to compile the C++ reference implementation (unless an appropriate wheel is available). If it fails it will fallback to the pure Python implementation which is about 10x slower on CPython.
Usage
>>> import jump
>>> jump.hash(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
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for jump_consistent_hash-3.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a67636a856c5d852e07279a6da6b7700650aea21bc841562a348597f8ee9d98b |
|
MD5 | 30b875764aa13fec086d180811f96687 |
|
BLAKE2b-256 | 6d074a86f6870e24269f3028b0fbdad6691fc4aceb8d62b1f13abcc0ff5e5e62 |
Hashes for jump_consistent_hash-3.0.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7872bfb4af9aa872f2437585116445b56e7f19e999962ace652eb91c3811003 |
|
MD5 | dbdaf694ede7130ceb848d381f1343d6 |
|
BLAKE2b-256 | d0d1abf22e3a876320981a5e762519de65215cc4aa105cb01f7cebbb98661f55 |
Hashes for jump_consistent_hash-3.0.1-cp27-cp27m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1305caf2707a7ea99c02cea83260bce9ea97900a75257b280c59482d4309b357 |
|
MD5 | a4ba2044b4475c189f2f754ce0818e08 |
|
BLAKE2b-256 | b6e6e30a5428e88925652af5e800ab04c96a4cfe95e4ba5fe16fd08794965f18 |