From 033fb554bec6523beb638965dc8f4adb96887332 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Sun, 30 May 2010 01:38:56 +0200 Subject: [PATCH] expose extra functionality from ziplist.c --- ziplist.c | 19 +++++++++++++++---- ziplist.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ziplist.c b/ziplist.c index 48ec2a34..4bc4f75c 100644 --- a/ziplist.c +++ b/ziplist.c @@ -432,6 +432,12 @@ unsigned char *ziplistNext(unsigned char *p) { return (p[0] == ZIP_END) ? NULL : p+zipRawEntryLength(p); } +/* Return pointer to previous entry in ziplist. */ +unsigned char *ziplistPrev(unsigned char *p) { + zlentry entry = zipEntry(p); + return (entry.prevrawlen == 0) ? NULL : p-entry.prevrawlen; +} + /* Get entry pointer to by 'p' and store in either 'e' or 'v' depending * on the encoding of the entry. 'e' is always set to NULL to be able * to find out whether the string pointer or the integer value was set. @@ -455,10 +461,9 @@ unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long return 1; } -/* Delete a range of entries from the ziplist. */ -unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num) { - unsigned char *p = ziplistIndex(zl,index); - return p == NULL ? zl : __ziplistDelete(zl,p,num); +/* Insert an entry at "p". */ +unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, char *s, unsigned int slen) { + return __ziplistInsert(zl,p,s,slen); } /* Delete a single entry from the ziplist, pointed to by *p. @@ -474,6 +479,12 @@ unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p) { return zl; } +/* Delete a range of entries from the ziplist. */ +unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num) { + unsigned char *p = ziplistIndex(zl,index); + return (p == NULL) ? zl : __ziplistDelete(zl,p,num); +} + /* Compare entry pointer to by 'p' with 'entry'. Return 1 if equal. */ unsigned int ziplistCompare(unsigned char *p, char *sstr, unsigned int slen) { zlentry entry; diff --git a/ziplist.h b/ziplist.h index 29be0b40..8d37a8f5 100644 --- a/ziplist.h +++ b/ziplist.h @@ -6,8 +6,10 @@ unsigned char *ziplistPush(unsigned char *zl, char *s, unsigned int slen, int wh unsigned char *ziplistPop(unsigned char *zl, sds *target, int where); unsigned char *ziplistIndex(unsigned char *zl, int index); unsigned char *ziplistNext(unsigned char *p); +unsigned char *ziplistPrev(unsigned char *p); unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long long *sval); unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p); +unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, char *s, unsigned int slen); unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num); unsigned int ziplistCompare(unsigned char *p, char *entry, unsigned int elen); unsigned int ziplistLen(unsigned char *zl); -- 2.45.2