Add a consistent hash function to util/hash
commitede6eda63709969a1a0020f2b116d3a77c31ab6e
authorRick Lavoie <rlavoie@fb.com>
Tue, 15 Mar 2022 17:51:18 +0000 (15 10:51 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 15 Mar 2022 17:51:18 +0000 (15 10:51 -0700)
tree1349733df15575e49a193f78eb65bcd333e46671
parenteb18d6764f8c5de67e13a0ad566bfeb64eb6695b
Add a consistent hash function to util/hash

Summary:
Add a consistent hash function to util/hash. A consistent hash maps a
key to some set of buckets (like any hash), but has the added property
that changing the number of buckets tends to only minimally disturb
the mapping. That is, most keys will continue to map to the same
bucket they did previously. This is opposed to normal hash functions,
where any change tends to radically change the output (by design).

Use an algorithm from "A Fast, Minimal Memory, Consistent Hash
Algorithm" by John Lamping and Eric Veach. This algorithm is compact
and relatively quick. It also doesn't require data structures scaling
with the number of buckets (like many older consistent hashes like
rendezvous hashing).

Consistent hashing is useful with extern-worker because you want to
batch work together in ways that is robust against new data being
added/removed across runs.

Reviewed By: edwinsmith

Differential Revision: D34746411

fbshipit-source-id: 79beb1c9015afba385e87830f9f44070c39ce3f9
hphp/util/hash.cpp
hphp/util/hash.h