Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

HashRing

9 exports Since v3.19.0 Source

Combinators

Since v3.19.0

Add a new node to the ring. If the node already exists in the ring, it will be updated. For example, you can use this to update the node's weight.

Signature

declare const add: {
<A extends PrimaryKey>(node: A, options?: {
readonly weight?: number;
}): (self: HashRing<A>) => HashRing<A>;
<A extends PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number;
}): HashRing<A>;
}
Since v3.19.0

Add new nodes to the ring. If a node already exists in the ring, it will be updated. For example, you can use this to update the node's weight.

Signature

declare const addMany: {
<A extends PrimaryKey>(nodes: Iterable<A>, options?: {
readonly weight?: number;
}): (self: HashRing<A>) => HashRing<A>;
<A extends PrimaryKey>(self: HashRing<A>, nodes: Iterable<A>, options?: {
readonly weight?: number;
}): HashRing<A>;
}
Since v3.19.0

Gets the node which should handle the given input. Returns undefined if the hashring has no elements with weight.

Signature

declare function get<A extends PrimaryKey>(self: HashRing<A>, input: string): A | undefined
Since v3.19.0

Distributes count shards across the nodes in the ring, attempting to balance the number of shards allocated to each node. Returns undefined if the hashring has no elements with weight.

Signature

declare function getShards<A extends PrimaryKey>(self: HashRing<A>, count: number): Array<A> | undefined
Since v3.19.0

Signature

declare const has: {
<A extends PrimaryKey>(node: A): (self: HashRing<A>) => boolean;
<A extends PrimaryKey>(self: HashRing<A>, node: A): boolean;
}
Since v3.19.0

Removes the node from the ring. No-op's if the node does not exist.

Signature

declare const remove: {
<A extends PrimaryKey>(node: A): (self: HashRing<A>) => HashRing<A>;
<A extends PrimaryKey>(self: HashRing<A>, node: A): HashRing<A>;
}

Constructors

Since v3.19.0

Signature

declare function make<A extends PrimaryKey>(options?: {
readonly baseWeight?: number;
}): HashRing<A>

Guards

Signature

declare function isHashRing(u: unknown): u is HashRing<any>

Models

HashRing

interface
Since v3.19.0

Signature

interface HashRing<A extends PrimaryKey.PrimaryKey> extends Pipeable, "/home/runner/work/website/website/.effect-source-v3/packages/effect/src/Iterable"<A> {
readonly "~effect/cluster/HashRing": "~effect/cluster/HashRing";
readonly baseWeight: number;
readonly nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
totalWeightCache: number;
}