<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, input: string):
| A
| undefinedGets the node which should handle the given input. Returns undefined if the hashring has no elements with weight.
When to use
Use to route a single string input key to the current ring member responsible for that key.
export const const get: <
A extends PrimaryKey.PrimaryKey
>(
self: HashRing<A>,
input: string
) => A | undefined
Gets the node which should handle the given input. Returns undefined if
the hashring has no elements with weight.
When to use
Use to route a single string input key to the current ring member responsible
for that key.
get = <function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, input: string): A | undefinedA 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>, input: string): A | undefinedA>, input: stringinput: string): function (type parameter) A in <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, input: string): A | undefinedA | undefined => {
if (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.HashRing<A extends PrimaryKey.PrimaryKey>.ring: [hash: number, node: string][]ring.Array<[hash: number, node: string]>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 0) {
return var undefinedundefined
}
const const index: numberindex = function getIndexForInput<
A extends PrimaryKey.PrimaryKey
>(
self: HashRing<A>,
hash: number,
exclude?: ReadonlySet<string> | undefined
): readonly [index: number, distance: number]
getIndexForInput(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, import HashHash.string(input: stringinput))[0]
const const node: stringnode = 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.HashRing<A extends PrimaryKey.PrimaryKey>.ring: [hash: number, node: string][]ring[const index: numberindex][1]!
return 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.HashRing<A>.nodes: Map<string, [node: A, weight: number]>nodes.Map<string, [node: A, weight: number]>.get(key: string): [node: A, weight: number] | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(const node: stringnode)![0]
}