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.

Source Distribution

ConsistentHashing-0.2.0.tar.gz (2.4 kB view hashes)

Uploaded Source

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