<A extends PrimaryKey.PrimaryKey>(
node: A,
options?: { readonly weight?: number | undefined }
): (self: HashRing<A>) => HashRing<A>
<A extends PrimaryKey.PrimaryKey>(
self: HashRing<A>,
node: A,
options?: { readonly weight?: number | undefined }
): HashRing<A>Adds 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.
When to use
Use to register one node in a HashRing so lookups and shard assignments can
return it, or update that node's weight.
Details
Nodes are matched by PrimaryKey.value. The weight defaults to 1 and is
clamped to at least 0.1.
Gotchas
This mutates and returns the same ring instance.
export const const add: {
<A extends PrimaryKey.PrimaryKey>(
node: A,
options?: {
readonly weight?: number | undefined
}
): (self: HashRing<A>) => HashRing<A>
<A extends PrimaryKey.PrimaryKey>(
self: HashRing<A>,
node: A,
options?: {
readonly weight?: number | undefined
}
): HashRing<A>
}
Adds 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.
When to use
Use to register one node in a HashRing so lookups and shard assignments can
return it, or update that node's weight.
Details
Nodes are matched by PrimaryKey.value. The weight defaults to 1 and is
clamped to at least 0.1.
Gotchas
This mutates and returns the same ring instance.
add: {
<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A, options?: {
readonly weight?: number | undefined;
}): (self: HashRing<A>) => HashRing<A>
A extends import PrimaryKeyPrimaryKey.PrimaryKey>(node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A, options?: {
readonly weight?: number | undefined;
}): (self: HashRing<A>) => HashRing<A>
A, options: | {
readonly weight?: number | undefined
}
| undefined
options?: {
readonly weight?: number | undefinedweight?: number | undefined
}): (self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A, options?: {
readonly weight?: number | undefined;
}): (self: HashRing<A>) => HashRing<A>
A>) => interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(node: A, options?: {
readonly weight?: number | undefined;
}): (self: HashRing<A>) => HashRing<A>
A>
<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A extends import PrimaryKeyPrimaryKey.PrimaryKey>(self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A>, node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A, options: | {
readonly weight?: number | undefined
}
| undefined
options?: {
readonly weight?: number | undefinedweight?: number | undefined
}): interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A>
} = import dualdual((args: anyargs) => const isHashRing: (
u: unknown
) => u is HashRing<any>
Checks whether a value is a HashRing.
When to use
Use to narrow an unknown value before treating it as a HashRing, such as
values crossing an untyped boundary.
Details
The guard checks for the module's internal TypeId property and narrows to
HashRing<any>.
Gotchas
This is a structural type-id check; it does not validate the ring's nodes,
ring, or weight state.
isHashRing(args: anyargs[0]), <function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A extends import PrimaryKeyPrimaryKey.PrimaryKey>(self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A>, node: A extends PrimaryKey.PrimaryKeynode: function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A, options: | {
readonly weight?: number | undefined
}
| undefined
options?: {
readonly weight?: number | undefinedweight?: number | undefined
}): interface HashRing<A extends PrimaryKey.PrimaryKey>A weighted consistent-hashing ring for assigning inputs to nodes with stable
remapping as nodes are added or removed.
When to use
Use to maintain a mutable weighted hash ring for routing keys or shards to
nodes identified by PrimaryKey.
Details
Nodes are identified by their PrimaryKey value and can be iterated from the
ring.
HashRing<function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A, options?: {
readonly weight?: number | undefined;
}): HashRing<A>
A> => const addMany: {
<A extends PrimaryKey.PrimaryKey>(
nodes: Iterable<A>,
options?: {
readonly weight?: number | undefined
}
): (self: HashRing<A>) => HashRing<A>
<A extends PrimaryKey.PrimaryKey>(
self: HashRing<A>,
nodes: Iterable<A>,
options?: {
readonly weight?: number | undefined
}
): HashRing<A>
}
addMany(self: HashRing<A>(parameter) self: {
baseWeight: number;
totalWeightCache: number;
nodes: Map<string, [node: A, weight: number]>;
ring: Array<[hash: number, node: string]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self, [node: A extends PrimaryKey.PrimaryKeynode], options: | {
readonly weight?: number | undefined
}
| undefined
options))