Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A simple implement of consistent hashing.

Project Description

Introduction

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=["122.225.109.103","221.236.5.135","58.58.179.52","61.174.51.204","222.186.31.234","182.74.141.242","179.107.90.135"], slotSize=10000, virtualNode=2)
>>> inst.getAllNodes()
['122.225.109.103', '221.236.5.135', '58.58.179.52', '61.174.51.204', '222.186.31.234', '182.74.141.242', '179.107.90.135']
>>> inst.addNode('1.1.1.1')
True
>>> inst.getNode('1')
'61.174.51.204'
>>> inst.getNode('a')
'122.225.109.103'
>>> inst.getNode('hello')
'61.174.51.204'
>>> inst.getNode('consistenthashing')
'1.1.1.1'
>>> inst.getVirtualNodeNumber()
2
>>> inst.getVirtualNodes('221.236.5.135')
['221.236.5.135_virtual1', '221.236.5.135_virtual2']
>>> inst.removeNode('122.225.109.103')
True
>>> inst.addNode('pypi.python.org')
True
>>> inst.getAllNodes()
['221.236.5.135', '58.58.179.52', '61.174.51.204', '222.186.31.234', '182.74.141.242', '179.107.90.135', '1.1.1.1', 'pypi.python.org']

Referencek

Release History

Release History

This version
History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ConsistentHashing-0.2.2.tar.gz (2.5 kB) Copy SHA256 Checksum SHA256 Source Dec 8, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting