Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
b98c33db
Commit
b98c33db
authored
Feb 05, 2015
by
antirez
Browse files
dict.c: dictGetRandomKeys() optimization for big->small table case.
Related to issue #2306.
parent
e004ac8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dict.c
View file @
b98c33db
...
@@ -704,7 +704,14 @@ unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count) {
...
@@ -704,7 +704,14 @@ unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count) {
/* Invariant of the dict.c rehashing: up to the indexes already
/* Invariant of the dict.c rehashing: up to the indexes already
* visited in ht[0] during the rehashing, there are no populated
* visited in ht[0] during the rehashing, there are no populated
* buckets, so we can skip ht[0] for indexes between 0 and idx-1. */
* buckets, so we can skip ht[0] for indexes between 0 and idx-1. */
if
(
j
==
0
&&
i
<
d
->
rehashidx
)
continue
;
if
(
tables
==
2
&&
j
==
0
&&
i
<
d
->
rehashidx
)
{
/* Moreover, if we are currently out of range in the second
* table, there will be no elements in both tables up to
* the current rehashing index, so we jump if possible.
* (this happens when going from big to small table). */
if
(
i
>=
d
->
ht
[
1
].
size
)
i
=
d
->
rehashidx
;
continue
;
}
if
(
i
>=
d
->
ht
[
j
].
size
)
continue
;
/* Out of range for this table. */
if
(
i
>=
d
->
ht
[
j
].
size
)
continue
;
/* Out of range for this table. */
dictEntry
*
he
=
d
->
ht
[
j
].
table
[
i
];
dictEntry
*
he
=
d
->
ht
[
j
].
table
[
i
];
while
(
he
)
{
while
(
he
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment