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

Function updateTotalWeight

packages/effect/src/HashRing.ts:188–195  ·  view source on GitHub ↗
(self: HashRing<A>)

Source from the content-addressed store, hash-verified

186
187// Sum in key order to avoid history-dependent floating-point rounding.
188function updateTotalWeight<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>) {
189 const keys = Array.from(self.nodes.keys()).sort()
190 let total = 0
191 for (let i = 0; i < keys.length; i++) {
192 total += self.nodes.get(keys[i])![1]
193 }
194 self.totalWeightCache = total
195}
196
197/**
198 * Adds a new node to the ring. If the node already exists in the ring, it

Callers 1

HashRing.tsFile · 0.85

Calls 3

fromMethod · 0.80
keysMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected