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
2424490f
Commit
2424490f
authored
Mar 04, 2010
by
Pieter Noordhuis
Browse files
use 1-based rank across zsl*Rank functions consistently
parent
9212eafd
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
2424490f
...
...
@@ -5055,16 +5055,12 @@ static unsigned long zslDeleteRange(zskiplist *zsl, double min, double max, dict
}
/* Delete all the elements with rank between start and end from the skiplist.
* Start and end are inclusive. */
* Start and end are inclusive.
Note that start and end need to be 1-based
*/
static unsigned long zslDeleteRangeByRank(zskiplist *zsl, unsigned int start, unsigned int end, dict *dict) {
zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;
unsigned long traversed = 0, removed = 0;
int i;
/* start and end are given 0-based, but zsl uses 1-based
* ranks internally */
start
++
;
end
++
;
x = zsl->header;
for (i = zsl->level-1; i >= 0; i--) {
while (x->forward[i] && (traversed + (i > 0 ? x->span[i-1] : 1)) < start) {
...
...
@@ -5360,7 +5356,9 @@ static void zremrangebyrankCommand(redisClient *c) {
}
if (end >= llen) end = llen-1;
deleted
=
zslDeleteRangeByRank
(
zs
->
zsl
,
start
,
end
,
zs
->
dict
);
/* increment start and end because zsl*Rank functions
* use 1-based rank */
deleted = zslDeleteRangeByRank(zs->zsl,start+1,end+1,zs->dict);
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
server.dirty += deleted;
addReplyLong(c, deleted);
...
...
@@ -5413,9 +5411,9 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
/* check if starting point is trivial, before searching
* the element in log(N) time */
if (reverse) {
ln
=
start
==
0
?
zsl
->
tail
:
zslGetElementByRank
(
zsl
,
llen
-
start
);
ln = start == 0 ? zsl->tail : zslGetElementByRank(zsl, llen
-
start);
} else {
ln
=
start
==
0
?
zsl
->
header
->
forward
[
0
]
:
zslGetElementByRank
(
zsl
,
start
+
1
);
ln = start == 0 ? zsl->header->forward[0] : zslGetElementByRank(zsl, start
+
1);
}
/* Return the result in form of a multi-bulk reply */
...
...
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