Giter VIP home page Giter VIP logo

chash's Introduction

Consistent Hashing Clojure Library

CHash is a yet another consistent hashing library in Clojure, heavily inspired by the implementation in Riak Core.

Project Maturity

CHash is not a young project and based on the consistent hashing implementation from Riak Core which is mature.

Artifacts

CHash artifacts are released to Clojars. If you are using Maven, add the following repository definition to your pom.xml:

<repository>
  <id>clojars.org</id>
  <url>http://clojars.org/repo</url>
</repository>

The Most Recent Release

With Leiningen:

[clojurewerkz/chash "1.1.0"]

With Maven:

<dependency>
  <groupId>clojurewerkz</groupId>
  <artifactId>chash</artifactId>
  <version>1.1.0</version>
</dependency>

Documentation & Examples

CHash is a very small library so there are no documentation guides.

(require '[clojurewerkz.chash.ring :as ch])

;; create a new ring with 64 partitions and a seed node (value)
(ch/fresh 64 "seed")

;; update a partition
(let [r (ch/fresh 64 "seed")]
  (ch/update r 0 "node2"))

;; retrieve 3 partitions in order starting at the given point on the ring
(let [r (ch/fresh 64 "seed")]
  (ch/successors r (ch/key-of 0) 3))

;; check if a particular node claims any partitions in the ring
(let [r (ch/fresh 64 "seed")]
  (ch/claimant? r "node2"))

;; given a key as an integer, get the next ring partition
(let [r (ch/fresh 64 "seed")]
  (ch/next-index r (ch/key-of 128)))

;; randomized merging of two rings. When two nodes claim the same partition,
;; the owner in the resulting ring is selected randomly
(let [r1 (ch/fresh 64 "node1")
      r2 (ch/fresh 64 "node2")]
  (ch/merge r1 r2))

See documentation strings for clojurewerkz.chash.core functions and our test suite.

Supported Clojure Versions

CHash requires Clojure 1.4 or later.

Continuous Integration Status

Continuous Integration status

CHash Is a ClojureWerkz Project

CHash is part of the group of Clojure libraries known as ClojureWerkz, together with Monger, Welle, Langohr, Elastisch, Neocons and several others.

Development

CHash uses Leiningen 2. Make sure you have it installed and then run tests against supported Clojure versions using

lein all test

Then create a branch and make your changes on it. Once you are done with your changes and all tests pass, submit a pull request on Github.

License

Copyright (C) 2012-2016 Michael S. Klishin, Alex Petrov, and the ClojureWerkz team.

Double licensed under the Eclipse Public License (the same as Clojure) or the Apache Public License 2.0.

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.