Skip to main content

A simple implement of consistent hashing.

Project description


Consistent hashing is a special kind of hashing such that when a hash table is resized and consistent hashing is used, only few keys need to be remapped. In contrast, in most traditional hash tables, a change in the number of array slots causes nearly all keys to be remapped.

ConsistentHashing is a very simple implement of concistent hashing.

Usage examples

>>> from consistenthashing import consistenthashing
>>> inst = consistenthashing(nodes=["","","","","","",""], slotSize=10000, virtualNode=2)
>>> inst.getAllNodes()
['', '', '', '', '', '', '']
>>> inst.addNode('')
>>> inst.getNode('1')
>>> inst.getNode('a')
>>> inst.getNode('hello')
>>> inst.getNode('consistenthashing')
>>> inst.getVirtualNodeNumber()
>>> inst.getVirtualNodes('')
['', '']
>>> inst.removeNode('')
>>> inst.addNode('')
>>> inst.getAllNodes()
['', '', '', '', '', '', '', '']


Project details

Download files

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

Files for ConsistentHashing, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size ConsistentHashing-0.2.2.tar.gz (2.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page