MCPcopy Create free account
hub / github.com/Effect-TS/effect / addNodesToRing

Function addNodesToRing

packages/effect/src/HashRing.ts:173–185  ·  view source on GitHub ↗
(self: HashRing<A>, keys: Array<string>, weight: number)

Source from the content-addressed store, hash-verified

171)
172
173function addNodesToRing<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, keys: Array<string>, weight: number) {
174 for (let i = weight; i > 0; i--) {
175 for (let j = 0; j < keys.length; j++) {
176 const key = keys[j]
177 self.ring.push([
178 Hash.string(`${key}:${i}`),
179 key
180 ])
181 }
182 }
183 // Break hash ties by node key to avoid insertion-order dependence.
184 self.ring.sort((a, b) => a[0] - b[0] || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))
185}
186
187// Sum in key order to avoid history-dependent floating-point rounding.
188function updateTotalWeight<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>) {

Callers 1

HashRing.tsFile · 0.85

Calls 2

pushMethod · 0.65
stringMethod · 0.45

Tested by

no test coverage detected