A consistent hashing implementation using sorted-map as the core datastructure for amortized constant time lookups.
A consistent hashing implementation using sorted-map as the core datastructure for amortized constant time lookups.
(delete ring key)
Deletes all nodes inserted by insert
from the ring.
key
- a string key to identify the node to delete
Deletes all nodes inserted by `insert` from the ring. `key` - a string key to identify the node to delete
(insert ring key node)
Inserts replication-factor
number of nodes into the ring.
key
- a string key to identify this node
node
- a value representing a node in the cluster
Inserts `replication-factor` number of nodes into the ring. `key` - a string key to identify this node `node` - a value representing a node in the cluster
(lookup ring key)
Chooses a node in the cluster to be responsible for the given key.
This function runs in amortized constant time as it is using subseq
on
a sorted-map
.
key
- an arbitrary string key
Chooses a node in the cluster to be responsible for the given key. This function runs in amortized constant time as it is using `subseq` on a `sorted-map`. `key` - an arbitrary string key
(ring replication-factor)
(ring replication-factor hash-fn)
Creates a consistent hashing ring
replication-factor - specifies the number of times a node will be repeated in the ring.
A larger number will ensure that inserting or deleting a node will
rebalance load evenly across all other nodes in the cluster. If the
number is too large insert
/delete
are slower (but not lookup
).
A good rule of thumb is to choose a multiple of the maximum number of nodes in the cluster (e.g. max-cluster-size * 4).
hash-fn
- a function to hash string keys (defaults to digest/sha-256
)
Creates a consistent hashing ring replication-factor - specifies the number of times a node will be repeated in the ring. A larger number will ensure that inserting or deleting a node will rebalance load evenly across all other nodes in the cluster. If the number is too large `insert`/`delete` are slower (but not `lookup`). A good rule of thumb is to choose a multiple of the maximum number of nodes in the cluster (e.g. max-cluster-size * 4). `hash-fn` - a function to hash string keys (defaults to `digest/sha-256`)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close