ExRingRing.Infrastructure.HashRing.Static (ExRingRing v0.2.0)

Copy Markdown View Source

Static hash ring implementation using sorted array (tuple).

Optimized for read-heavy workloads. Adding/removing nodes requires O(N log N) time but finding nodes is a guaranteed O(log N) lower-bound binary search.

Summary

Functions

Adds nodes to the ring.

Folds over nodes starting from item's position.

Gets all nodes.

Gets non-phantom node count.

Hashes an item.

Creates a new static hash ring.

Removes nodes from the ring.

Types

state()

@type state() :: %{
  vnodes: tuple(),
  base: ExRingRing.Infrastructure.HashRing.Base.state()
}

Functions

add_nodes(nodes, state)

@spec add_nodes([ExRingRing.Domain.Entities.Node.t()], state()) :: state()

Adds nodes to the ring.

fold(fun, item, acc, state)

@spec fold(fun(), term(), term(), state()) :: term()

Folds over nodes starting from item's position.

get_nodes(state)

@spec get_nodes(state()) :: %{required(term()) => ExRingRing.Domain.Entities.Node.t()}

Gets all nodes.

get_non_phantom_node_count(state)

@spec get_non_phantom_node_count(state()) :: non_neg_integer()

Gets non-phantom node count.

hash(item, state)

@spec hash(term(), state()) :: non_neg_integer()

Hashes an item.

make(nodes, config)

Creates a new static hash ring.

remove_nodes(keys, state)

@spec remove_nodes([atom() | binary() | integer()], state()) :: state()

Removes nodes from the ring.