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 hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page