-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsistent-hash.d.ts
More file actions
51 lines (46 loc) · 1.45 KB
/
consistent-hash.d.ts
File metadata and controls
51 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* ConsistentHash provides an implementation of consistent hashing using virtual nodes
* for improved key distribution. It maintains a ring structure of hashed virtual node values,
* mapping them to their corresponding real nodes.
*
* @module consistent-hash
*/
declare class ConsistentHash {
/**
* Create a new ConsistentHash instance.
*
* @param options - Configuration options.
* @param options.virtualNodes - Number of virtual nodes per real node (default is 100).
*/
constructor(options?: { virtualNodes?: number });
/**
* Add a new node to the hash ring.
*
* @param node - The node identifier.
* @throws Will throw an error if the node is not a non-empty string or already exists.
*/
addNode(node: string): void;
/**
* Remove a node and its associated virtual nodes from the hash ring.
*
* @param node - The node identifier.
* @throws Will throw an error if the node does not exist.
*/
removeNode(node: string): void;
/**
* Get the node responsible for a given key.
* Returns null if no nodes are present.
*
* @param key - The key to look up.
* @returns The node responsible for the key, or null if none exists.
* @throws Will throw an error if the key is not a non-empty string.
*/
getNode(key: string): string | null;
/**
* Get the number of real nodes in the hash ring.
*
* @returns The count of real nodes.
*/
size(): number;
}
export default ConsistentHash;