Libmemcached can use a cluster of servers as a backend. Each key is stored/read on only one server. The client determines which server to store/read each key based on a hash of the key. The hash value is a 32-bit integer whose modulus with the number of servers results in an integer in the range (0, number of servers). This is a pretty simple, but thoroughly useful, way to (roughly and likely mostly) evenly bucketize strings.
So here’s the function. It accepts a string key and the interval size to use as a modulus for the integer hash value.