From 1613f7a57250c318c20292ea33746341b30031c7 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 18 Feb 2019 18:38:40 +0100 Subject: [PATCH] Limit sampling size in dictGetFairRandomKey(). This way the implementation is almost as fast as the original one, but the distribution is not too bad. --- src/dict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dict.c b/src/dict.c index 6844e6c8e..ce48eb419 100644 --- a/src/dict.c +++ b/src/dict.c @@ -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);