ykayacan / hashing-utils

A basic Java implementation of Consistent Hashing, Rendezvous Hashing and Weighted Rendezvous Hashing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hashing Utils

Publish Release Publish Snapshot GitHub release (latest by date) GitHub

Table of Contents

About

A basic Java implementation of Consistent Hashing, Rendezvous Hashing and Weighted Rendezvous Hashing.

Getting Started

Latest Stable Releases

GitHub release (latest by date)

Gradle

dependencies {
  implementation 'io.github.ykayacan.hashing:hashing-api:LATEST_VERSION'
  implementation 'io.github.ykayacan.hashing:hashing-consistent:LATEST_VERSION'
  implementation 'io.github.ykayacan.hashing:hashing-rendezvous:LATEST_VERSION'
}

Maven

<dependencies>
  <dependency>
    <groupId>io.github.ykayacan.hashing</groupId>
    <artifactId>hashing-api</artifactId>
    <version>LATEST_VERSION</version>
  </dependency>

  <dependency>
    <groupId>io.github.ykayacan.hashing</groupId>
    <artifactId>hashing-consistent</artifactId>
    <version>LATEST_VERSION</version>
  </dependency>

  <dependency>
    <groupId>io.github.ykayacan.hashing</groupId>
    <artifactId>hashing-rendezvous</artifactId>
    <version>LATEST_VERSION</version>
  </dependency>
</dependencies>

Snapshots

You can access the latest snapshot by adding the repository https://oss.sonatype.org/content/repositories/snapshots to your build.

Snapshots of the development version are available in Sonatype's snapshots repository.

Usage

Consistent Hashing

NodeRouter<PhysicalNode> router = 
    ConsistentNodeRouter.create(15, MurMurHashFunction.create());

List<PhysicalNode> initialNodes = 
    Arrays.asList(PhysicalNode.of("node1"), PhysicalNode.of("node2"));

router.addNodes(initialNodes);

// get
Optional<PhysicalNode> nodeOpt = router.getNode("node1");

// add
router.addNode(PhysicalNode.of("node3"));

// remove
router.removeNode("node1");

Rendezvous Hashing

NodeRouter<WeightedNode> router = RendezvousNodeRouter.create(
    MurMurHashFunction.create(), DefaultRendezvousStrategy.create());

List<WeightedNode> initialNodes = 
    Arrays.asList(WeightedNode.of("node1"), WeightedNode.of("node2"));

router.addNodes(initialNodes);

// get
Optional<WeightedNode> nodeOpt = router.getNode("node1");

// add
router.addNode(WeightedNode.of("node3"));

// remove
router.removeNode("node1");

License

Copyright 2019 Yasin Sinan Kayacan

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A basic Java implementation of Consistent Hashing, Rendezvous Hashing and Weighted Rendezvous Hashing.

License:Apache License 2.0


Languages

Language:Java 100.0%