Limit sampling size in dictGetFairRandomKey().

This way the implementation is almost as fast as the original one, but
the distribution is not too bad.
This commit is contained in:
antirez 2019-02-18 18:38:40 +01:00
parent 61a01793ed
commit 1613f7a572

View File

@ -750,7 +750,7 @@ unsigned int dictGetSomeKeys(dict *d, dictEntry **des, unsigned int count) {
* that may be constituted of N buckets with chains of different lengths
* appearing one after the other. Then we report a random element in the range.
* In this way we smooth away the problem of different chain lenghts. */
#define GETFAIR_NUM_ENTRIES 20
#define GETFAIR_NUM_ENTRIES 10
dictEntry *dictGetFairRandomKey(dict *d) {
dictEntry *entries[GETFAIR_NUM_ENTRIES];
unsigned int count = dictGetSomeKeys(d,entries,GETFAIR_NUM_ENTRIES);