Hyperlinkv0.8.0-beta.28

HashRing

HashRing.getconsteffect/HashRing.ts:297
<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.

combinatorsgetShards
export const get = <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, input: string): A | undefined => {
  if (self.ring.length === 0) {
    return undefined
  }
  const index = getIndexForInput(self, Hash.string(input))[0]
  const node = self.ring[index][1]!
  return self.nodes.get(node)![0]
}