/FlexibleDistribute

A PHP Class implements Consistent Hashing Algorithm

Primary LanguagePHPGNU General Public License v3.0GPL-3.0

#FlexibleDistribute

FlexibleDistribute is a simple, small and easy to use PHP class which implements Consistent hashing Algorithm.

##Installation

Just download the Class file and require it in your code, then .. Enjoy !

require 'FlexibleDistribute.php';

##Usage

// Create an object
$FD = new FlexibleDistribute();
// Add nodes
$FD->addNode('192.168.1.150');
$FD->addNode('192.168.1.151');

// Or just pass the nodes to the constructor
$FD = new FlexibleDistribute(array('192.168.1.150', '192.168.1.151'));

// get the node responsible for the key "a"
$FD->getNode("a");

// Remove node
$FD->removeNode('192.168.1.150');

##TODO

  • Binary search in getNode method
  • add weight to host as an array

##Contribution

feel free to contact me to contribute with me.

##Consistent Hashing explained