ExRingRing.Infrastructure.HashRing.Dynamic (ExRingRing v0.1.1)

Copy Markdown View Source

Dynamic hash ring implementation using balanced tree (gb_trees).

Optimized for write-heavy workloads. Adding/removing nodes is O(log N) but finding nodes is slightly slower than static implementation.

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 dynamic hash ring.

Removes nodes from the ring.

Types

state()

@type state() :: %{
  vnodes: :gb_trees.tree(),
  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 dynamic hash ring.

remove_nodes(keys, state)

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

Removes nodes from the ring.