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
2165ac55
Commit
2165ac55
authored
Mar 09, 2011
by
Pieter Noordhuis
Browse files
Helpers to move around in encoded sorted set
parent
f8224a4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
2165ac55
...
@@ -454,6 +454,44 @@ unsigned int zzlLength(robj *zobj) {
...
@@ -454,6 +454,44 @@ unsigned int zzlLength(robj *zobj) {
return ziplistLen(zl)/2;
return ziplistLen(zl)/2;
}
}
/* Move to next entry based on the values in eptr and sptr. Both are set to
* NULL when there is no next entry. */
void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr) {
unsigned char *_eptr, *_sptr;
redisAssert(*eptr != NULL && *sptr != NULL);
_eptr = ziplistNext(zl,*sptr);
if (_eptr != NULL) {
_sptr = ziplistNext(zl,_eptr);
redisAssert(_sptr != NULL);
} else {
/* No next entry. */
_sptr = NULL;
}
*eptr = _eptr;
*sptr = _sptr;
}
/* Move to the previous entry based on the values in eptr and sptr. Both are
* set to NULL when there is no next entry. */
void zzlPrev(unsigned char *zl, unsigned char **eptr, unsigned char **sptr) {
unsigned char *_eptr, *_sptr;
redisAssert(*eptr != NULL && *sptr != NULL);
_sptr = ziplistPrev(zl,*eptr);
if (_sptr != NULL) {
_eptr = ziplistPrev(zl,_sptr);
redisAssert(_eptr != NULL);
} else {
/* No previous entry. */
_eptr = NULL;
}
*eptr = _eptr;
*sptr = _sptr;
}
/* Returns if there is a part of the zset is in range. Should only be used
/* Returns if there is a part of the zset is in range. Should only be used
* internally by zzlFirstInRange and zzlLastInRange. */
* internally by zzlFirstInRange and zzlLastInRange. */
int zzlIsInRange(unsigned char *zl, zrangespec *range) {
int zzlIsInRange(unsigned char *zl, zrangespec *range) {
...
@@ -1218,35 +1256,24 @@ void zrangeGenericCommand(redisClient *c, int reverse) {
...
@@ -1218,35 +1256,24 @@ void zrangeGenericCommand(redisClient *c, int reverse) {
else
else
eptr = ziplistIndex(zl,2*start);
eptr = ziplistIndex(zl,2*start);
redisAssert(eptr != NULL);
sptr = ziplistNext(zl,eptr);
while (rangelen--) {
while (rangelen--) {
redisAssert(eptr != NULL);
redisAssert(eptr !=
NULL && sptr !=
NULL);
redisAssert(ziplistGet(eptr,&vstr,&vlen,&vlong));
redisAssert(ziplistGet(eptr,&vstr,&vlen,&vlong));
if (vstr == NULL)
if (vstr == NULL)
addReplyBulkLongLong(c,vlong);
addReplyBulkLongLong(c,vlong);
else
else
addReplyBulkCBuffer(c,vstr,vlen);
addReplyBulkCBuffer(c,vstr,vlen);
if (withscores) {
if (withscores)
sptr = ziplistNext(zl,eptr);
redisAssert(sptr != NULL);
addReplyDouble(c,zzlGetScore(sptr));
addReplyDouble(c,zzlGetScore(sptr));
}
if (reverse) {
if (reverse)
/* Move to previous element by moving to the score of previous
zzlPrev(zl,&eptr,&sptr);
* element. When NULL, we know there also is no element. */
else
sptr = ziplistPrev(zl,eptr);
zzlNext(zl,&eptr,&sptr);
if (sptr != NULL) {
eptr = ziplistPrev(zl,sptr);
redisAssert(eptr != NULL);
} else {
eptr = NULL;
}
} else {
sptr = ziplistNext(zl,eptr);
redisAssert(sptr != NULL);
eptr = ziplistNext(zl,sptr);
}
}
}
} else if (zobj->encoding == REDIS_ENCODING_RAW) {
} else if (zobj->encoding == REDIS_ENCODING_RAW) {
...
...
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