expose extra functionality from ziplist.c

This commit is contained in:
Pieter Noordhuis 2010-05-30 01:38:56 +02:00
parent 177a0a0b0d
commit 033fb554be
2 changed files with 17 additions and 4 deletions

View File

@ -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;

View File

@ -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);