Module concha

A consistent hashing library.

Description

A consistent hashing library. The output range of the ring is the same as what SHA-256 produces. Nodes and keys are mapped to the ring using SHA-256 as well.

Data Types

key()

key() = term()

node_entry()

node_entry() = term()

nodes()

nodes() = [node_entry()]

num_vnodes()

num_vnodes() = pos_integer()

ring()

abstract datatype: ring()

Function Index

add/2Adds a node (and its virtual nodes) to the ring.
contains/2Returns true if the given node is present in the ring, otherwise false.
lookup/2Returns the node associated with the given key.
members/1Returns the ordered list of nodes in the ring.
new/1Creates a new ring without virtual nodes.
new/2Creates a new ring with NumVNodes of virtual nodes.
remove/2Removes the given node (and its virtual nodes) from the ring if the node is present in the ring, otherwise does nothing.
size/1Returns the number of nodes (including virtual nodes) in the ring.

Function Details

add/2

add(Node::node_entry(), Ring::ring()) -> ring()

Adds a node (and its virtual nodes) to the ring. Returns the new ring.

contains/2

contains(Node::node_entry(), Ring::ring()) -> boolean()

Returns true if the given node is present in the ring, otherwise false.

lookup/2

lookup(Key::key(), Ring::ring()) -> node_entry() | {error, empty_ring}

Returns the node associated with the given key. Returns an error if the ring is empty.

members/1

members(Ring::ring()) -> nodes()

Returns the ordered list of nodes in the ring.

new/1

new(Nodes::nodes()) -> ring()

Creates a new ring without virtual nodes.

new/2

new(NumVNodes::num_vnodes(), Nodes::nodes()) -> ring()

Creates a new ring with NumVNodes of virtual nodes.

remove/2

remove(Node::node_entry(), Ring::ring()) -> ring()

Removes the given node (and its virtual nodes) from the ring if the node is present in the ring, otherwise does nothing. Returns the new ring.

size/1

size(Ring::ring()) -> non_neg_integer()

Returns the number of nodes (including virtual nodes) in the ring.


Generated by EDoc, Sep 2 2016, 15:19:14.