Commit 1613f7a5 authored by antirez's avatar antirez
Browse files

Limit sampling size in dictGetFairRandomKey().

This way the implementation is almost as fast as the original one, but
the distribution is not too bad.
parent 61a01793
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment