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

Copy Markdown View Source

Base module for hash ring implementations.

Contains shared logic for hash calculation, virtual node management, and node state.

Summary

Functions

Adds a node to base state.

Calculates virtual node count for a node.

Creates virtual nodes for a node.

Gets hash mask.

Gets all nodes.

Gets non-phantom node count.

Calculates hash for a term.

Creates base state from hash config.

Removes a node from base state.

Types

state()

@type state() :: %{
  nodes: %{required(term()) => ExRingRing.Domain.Entities.Node.t()},
  phantom_count: non_neg_integer(),
  virtual_node_count: pos_integer(),
  hash_mask: non_neg_integer(),
  hash_algorithm: atom()
}

Functions

add_node(node, state)

@spec add_node(ExRingRing.Domain.Entities.Node.t(), state()) :: state()

Adds a node to base state.

calc_virtual_node_count(node, map)

@spec calc_virtual_node_count(ExRingRing.Domain.Entities.Node.t(), state()) ::
  non_neg_integer()

Calculates virtual node count for a node.

create_virtual_nodes(node, start, end_seq, base)

Creates virtual nodes for a node.

get_hash_mask(map)

@spec get_hash_mask(state()) :: non_neg_integer()

Gets hash mask.

get_nodes(map)

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

Gets all nodes.

get_non_phantom_node_count(map)

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

Gets non-phantom node count.

hash(term, map)

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

Calculates hash for a term.

make_base_state(config)

@spec make_base_state(ExRingRing.Domain.ValueObjects.HashConfig.t()) :: state()

Creates base state from hash config.

remove_node(key, state)

@spec remove_node(atom() | binary() | integer(), state()) :: state()

Removes a node from base state.