mirror of
https://github.com/fluencelabs/redis
synced 2025-04-22 00:52:13 +00:00
allow pointer to be stored to current element when iterating over ziplist
This commit is contained in:
parent
ba5b4bde21
commit
924727d905
11
ziplist.c
11
ziplist.c
@ -120,12 +120,13 @@ unsigned char *ziplistIndex(unsigned char *zl, unsigned int index) {
|
|||||||
|
|
||||||
/* Store entry at current position in sds *value and return pointer
|
/* Store entry at current position in sds *value and return pointer
|
||||||
* to the next entry. */
|
* to the next entry. */
|
||||||
unsigned char *ziplistNext(unsigned char *p, unsigned char **entry, unsigned int *elen) {
|
unsigned char *ziplistNext(unsigned char *p, unsigned char **q, unsigned char **entry, unsigned int *elen) {
|
||||||
if (*p == ZIP_END) return NULL;
|
if (*p == ZIP_END) return NULL;
|
||||||
if (entry) {
|
if (entry) {
|
||||||
*elen = zipDecodeLength(p);
|
*elen = zipDecodeLength(p);
|
||||||
*entry = p+ZIP_LEN_BYTES(*elen);
|
*entry = p+ZIP_LEN_BYTES(*elen);
|
||||||
}
|
}
|
||||||
|
if (q != NULL) *q = p;
|
||||||
p += zipRawEntryLength(p);
|
p += zipRawEntryLength(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -198,7 +199,7 @@ int main(int argc, char **argv) {
|
|||||||
{
|
{
|
||||||
zl = createList();
|
zl = createList();
|
||||||
p = ziplistIndex(zl, 0);
|
p = ziplistIndex(zl, 0);
|
||||||
while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
|
while ((p = ziplistNext(p, NULL, &entry, &elen)) != NULL) {
|
||||||
printf("Entry: ");
|
printf("Entry: ");
|
||||||
fwrite(entry,elen,1,stdout);
|
fwrite(entry,elen,1,stdout);
|
||||||
printf(" (length %d)\n", elen);
|
printf(" (length %d)\n", elen);
|
||||||
@ -210,7 +211,7 @@ int main(int argc, char **argv) {
|
|||||||
{
|
{
|
||||||
zl = createList();
|
zl = createList();
|
||||||
p = ziplistIndex(zl, 1);
|
p = ziplistIndex(zl, 1);
|
||||||
while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
|
while ((p = ziplistNext(p, NULL, &entry, &elen)) != NULL) {
|
||||||
printf("Entry: ");
|
printf("Entry: ");
|
||||||
fwrite(entry,elen,1,stdout);
|
fwrite(entry,elen,1,stdout);
|
||||||
printf(" (length %d)\n", elen);
|
printf(" (length %d)\n", elen);
|
||||||
@ -222,7 +223,7 @@ int main(int argc, char **argv) {
|
|||||||
{
|
{
|
||||||
zl = createList();
|
zl = createList();
|
||||||
p = ziplistIndex(zl, 2);
|
p = ziplistIndex(zl, 2);
|
||||||
while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
|
while ((p = ziplistNext(p, NULL, &entry, &elen)) != NULL) {
|
||||||
printf("Entry: ");
|
printf("Entry: ");
|
||||||
fwrite(entry,elen,1,stdout);
|
fwrite(entry,elen,1,stdout);
|
||||||
printf(" (length %d)\n", elen);
|
printf(" (length %d)\n", elen);
|
||||||
@ -234,7 +235,7 @@ int main(int argc, char **argv) {
|
|||||||
{
|
{
|
||||||
zl = createList();
|
zl = createList();
|
||||||
p = ziplistIndex(zl, 3);
|
p = ziplistIndex(zl, 3);
|
||||||
if (ziplistNext(p, &entry, &elen) == NULL) {
|
if (ziplistNext(p, &entry, NULL, &elen) == NULL) {
|
||||||
printf("No entry\n");
|
printf("No entry\n");
|
||||||
} else {
|
} else {
|
||||||
printf("ERROR\n");
|
printf("ERROR\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user