(self: HashRing<A>, keys: Array<string>, weight: number)
| 167 | ) |
| 168 | |
| 169 | function addNodesToRing<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, keys: Array<string>, weight: number) { |
| 170 | for (let i = weight; i > 0; i--) { |
| 171 | for (let j = 0; j < keys.length; j++) { |
| 172 | const key = keys[j] |
| 173 | self.ring.push([ |
| 174 | Hash.string(`${key}:${i}`), |
| 175 | key |
| 176 | ]) |
| 177 | } |
| 178 | } |
| 179 | self.ring.sort((a, b) => a[0] - b[0]) |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Adds a new node to the ring. If the node already exists in the ring, it |