summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-02-18 18:38:40 +0100
committerantirez <antirez@gmail.com>2019-02-18 18:38:40 +0100
commit1613f7a57250c318c20292ea33746341b30031c7 (patch)
treef036296c1b48907ff64496972386a45c47bf51bb
parent61a01793ed23a2b1cb3c468bd4057ddc7ba0e739 (diff)
downloadredis-1613f7a57250c318c20292ea33746341b30031c7.tar.gz
Limit sampling size in dictGetFairRandomKey().
This way the implementation is almost as fast as the original one, but the distribution is not too bad.
-rw-r--r--src/dict.c2
1 files changed, 1 insertions, 1 deletions
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);