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:
parent
61a01793ed
commit
1613f7a572
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user