Interface NodeLocator<T>

Type Parameters:
T - node data type | 节点数据类型

Usage Examples | 使用示例:

// Locate a node for a given key
// 为给定键定位节点
NodeLocator<String> locator = consistentHash;
String node = locator.locate("my-key");

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: No - 空值安全: 否
All Known Implementing Classes:
ConsistentHash

public interface NodeLocator<T>
Node locator interface for consistent hash ring 一致性哈希环的节点定位器接口

Defines the contract for locating nodes on a consistent hash ring based on a key's hash value.

定义根据键的哈希值在一致性哈希环上定位节点的契约。

Features | 主要功能:

  • Single node location - 单节点定位
  • Multiple replica location - 多副本定位
  • Ring traversal - 环遍历
Since:
JDK 25, opencode-base-hash V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    getVirtualNode(long hashValue)
    Gets the virtual node at the specified position 获取指定位置的虚拟节点
    int
    Gets the total number of virtual nodes 获取虚拟节点总数
    boolean
    Checks if the ring is empty 检查环是否为空
    locate(long hashValue)
    Locates the node for a given hash value 为给定的哈希值定位节点
    locateAll(long hashValue, int count)
    Locates multiple nodes for replica placement 为副本放置定位多个节点
  • Method Details

    • locate

      T locate(long hashValue)
      Locates the node for a given hash value 为给定的哈希值定位节点
      Parameters:
      hashValue - hash value | 哈希值
      Returns:
      the node data, or null if ring is empty | 节点数据,如果环为空则返回null
    • locateAll

      List<T> locateAll(long hashValue, int count)
      Locates multiple nodes for replica placement 为副本放置定位多个节点

      Returns nodes in clockwise order from the hash position. Duplicate physical nodes are excluded.

      按哈希位置的顺时针顺序返回节点。排除重复的物理节点。

      Parameters:
      hashValue - hash value | 哈希值
      count - number of nodes to return | 要返回的节点数
      Returns:
      list of node data | 节点数据列表
    • getVirtualNode

      VirtualNode<T> getVirtualNode(long hashValue)
      Gets the virtual node at the specified position 获取指定位置的虚拟节点
      Parameters:
      hashValue - hash value | 哈希值
      Returns:
      virtual node, or null if ring is empty | 虚拟节点,如果环为空则返回null
    • isEmpty

      boolean isEmpty()
      Checks if the ring is empty 检查环是否为空
      Returns:
      true if empty | 如果为空返回true
    • getVirtualNodeCount

      int getVirtualNodeCount()
      Gets the total number of virtual nodes 获取虚拟节点总数
      Returns:
      virtual node count | 虚拟节点数量