IzumiSy / elm-consistent-hashing / ConsistentHashing

A pure Elm Consistent hashing module


type ConsistentHashing

A data structure for consistent hashing

new : Replica -> Node -> ConsistentHashing

Creates a new ConsistentHashing data

new function only takes one initial node at first. This interface is like non-empty list which aims to ensure one node always available at least for distribution.

If you want, you can add some more nodes one by one using add function.

add : Node -> ConsistentHashing -> ConsistentHashing

Adds a node

remove : Node -> ConsistentHashing -> Maybe ConsistentHashing

Removes a node

This function returns Nothing if all nodes were removed. remove function internally run linear removing of all replicated virtual nodes so that it possibly results in huge computation cost in case you give a big number of Replica.

getNode : Key -> ConsistentHashing -> Node

Gets one node by key

This function is implemented with Array internally so that looking up a possible node is done simply by Binary Search.