Giter Site home page Giter Site logo

rlrw's Introduction

Rendezvous or Lowest Random Weight (LRW) hashing

This is a Ruby implementation of LRW. It is a port of Ferd's LRW. Even if it is a port, it cannot be used with the original implementation as it uses another hash function.

This hashing mechanism allows you to consistently hash to a specific node without needing to do bucketing first a'la Consistent Hashing. It also guarantees as little key redistribution as possible.

Interface

The all/2 function gives an ordering of all nodes:

<= Rlrw::LRW.all("my_item", ["127.0.0.1", "255.0.0.1", "192.2.1.2", "192.198.2.1"])
=> ["255.0.0.1", "192.2.1.2", "127.0.0.1", "192.198.2.1"]
<= Rlrw::LRW.all("my_item", ["127.0.0.1","198.2.1.2","192.198.2.1","10.10.100.10"])
=> ["198.2.1.2", "10.10.100.10", "127.0.0.1", "192.198.2.1"]
<= Rlrw::LRW.all("my_item", ["127.0.0.1","192.198.2.1"])
=> ["127.0.0.1", "192.198.2.1"]
<= Rlrw::LRW.all("my_item", ["127.0.0.1","192.18.211.12","23.66.77.88","252.11.11.11"])
=> ["192.18.211.12", "23.66.77.88", "127.0.0.1", "252.11.11.11"]
<= Rlrw::LRW.all("my_other_item", ["127.0.0.1","192.18.211.12","23.66.77.88","252.11.11.11"])
=> ["252.11.11.11", "23.66.77.88", "192.18.211.12", "127.0.0.1"]
<= Rlrw::LRW.all("my_other_item", ["127.0.0.1","192.18.211.12","23.66.77.88","252.11.11.11"])
=> ["252.11.11.11", "23.66.77.88", "192.18.211.12", "127.0.0.1"]

The top/3 function returns a subset. It is using all/2 in its implementation

<= Rlrw::LRW.top("12123", ["127.0.0.1","255.0.0.1","198.2.1.2","192.198.2.1"], 2)
=> ["127.0.0.1", "198.2.1.2"]

Custom hashing functions can be passed by calling all/3 and top/3, where the argument of each function must be a lambda that accepts two arguments, key, and node and returns a number.

Test

$ bundle install
$ bundle exec rake

rlrw's People

Contributors

omarkj avatar

Stargazers

Damien Mathieu avatar

Watchers

James Cloos avatar  avatar

Forkers

jkakar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.