nodesFor method
The nodes holding key, best first.
Rendezvous hashing: score every node for this key and take the highest. Removing a node changes the winner only for keys it was winning, because the other nodes' scores for every other key are untouched.
Implementation
List<String> nodesFor(String key) {
final List<String> ranked = nodes.keys.toList()
..sort((String a, String b) {
final int byScore = _score(b, key).compareTo(_score(a, key));
// Ties broken by name, so placement is deterministic across processes
// rather than depending on map iteration order.
return byScore != 0 ? byScore : a.compareTo(b);
});
final int count = replicas > ranked.length ? ranked.length : replicas;
return List<String>.unmodifiable(ranked.take(count));
}