Lines Matching refs:zm
97 unsigned char *zm = zmalloc(2); in zipmapNew() local
99 zm[0] = 0; /* Length */ in zipmapNew()
100 zm[1] = ZIPMAP_END; in zipmapNew()
101 return zm; in zipmapNew()
138 static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, unsigned int klen, uns… in zipmapLookupRaw() argument
139 unsigned char *p = zm+1, *k = NULL; in zipmapLookupRaw()
164 if (totlen != NULL) *totlen = (unsigned int)(p-zm)+1; in zipmapLookupRaw()
202 static inline unsigned char *zipmapResize(unsigned char *zm, unsigned int len) { in zipmapResize() argument
203 zm = zrealloc(zm, len); in zipmapResize()
204 zm[len-1] = ZIPMAP_END; in zipmapResize()
205 return zm; in zipmapResize()
211 unsigned char *zipmapSet(unsigned char *zm, unsigned char *key, unsigned int klen, unsigned char *v… in zipmapSet() argument
219 p = zipmapLookupRaw(zm,key,klen,&zmlen); in zipmapSet()
222 zm = zipmapResize(zm, zmlen+reqlen); in zipmapSet()
223 p = zm+zmlen-1; in zipmapSet()
227 if (zm[0] < ZIPMAP_BIGLEN) zm[0]++; in zipmapSet()
237 offset = p-zm; in zipmapSet()
238 zm = zipmapResize(zm, zmlen-freelen+reqlen); in zipmapSet()
239 p = zm+offset; in zipmapSet()
257 offset = p-zm; in zipmapSet()
260 zm = zipmapResize(zm, zmlen); in zipmapSet()
261 p = zm+offset; in zipmapSet()
276 return zm; in zipmapSet()
281 unsigned char *zipmapDel(unsigned char *zm, unsigned char *key, unsigned int klen, int *deleted) { in zipmapDel() argument
283 unsigned char *p = zipmapLookupRaw(zm,key,klen,&zmlen); in zipmapDel()
286 memmove(p, p+freelen, zmlen-((p-zm)+freelen+1)); in zipmapDel()
287 zm = zipmapResize(zm, zmlen-freelen); in zipmapDel()
290 if (zm[0] < ZIPMAP_BIGLEN) zm[0]--; in zipmapDel()
296 return zm; in zipmapDel()
300 unsigned char *zipmapRewind(unsigned char *zm) { in zipmapRewind() argument
301 return zm+1; in zipmapRewind()
315 unsigned char *zipmapNext(unsigned char *zm, unsigned char **key, unsigned int *klen, unsigned char… in zipmapNext() argument
316 if (zm[0] == ZIPMAP_END) return NULL; in zipmapNext()
318 *key = zm; in zipmapNext()
319 *klen = zipmapDecodeLength(zm); in zipmapNext()
322 zm += zipmapRawKeyLength(zm); in zipmapNext()
324 *value = zm+1; in zipmapNext()
325 *vlen = zipmapDecodeLength(zm); in zipmapNext()
328 zm += zipmapRawValueLength(zm); in zipmapNext()
329 return zm; in zipmapNext()
334 int zipmapGet(unsigned char *zm, unsigned char *key, unsigned int klen, unsigned char **value, unsi… in zipmapGet() argument
337 if ((p = zipmapLookupRaw(zm,key,klen,NULL)) == NULL) return 0; in zipmapGet()
345 int zipmapExists(unsigned char *zm, unsigned char *key, unsigned int klen) { in zipmapExists() argument
346 return zipmapLookupRaw(zm,key,klen,NULL) != NULL; in zipmapExists()
350 unsigned int zipmapLen(unsigned char *zm) { in zipmapLen() argument
352 if (zm[0] < ZIPMAP_BIGLEN) { in zipmapLen()
353 len = zm[0]; in zipmapLen()
355 unsigned char *p = zipmapRewind(zm); in zipmapLen()
359 if (len < ZIPMAP_BIGLEN) zm[0] = len; in zipmapLen()
367 size_t zipmapBlobLen(unsigned char *zm) { in zipmapBlobLen() argument
369 zipmapLookupRaw(zm,NULL,0,&totlen); in zipmapBlobLen()
409 unsigned char *zm; in zipmapTest() local
414 zm = zipmapNew(); in zipmapTest()
416 zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL); in zipmapTest()
417 zm = zipmapSet(zm,(unsigned char*) "surname",7, (unsigned char*) "foo",3,NULL); in zipmapTest()
418 zm = zipmapSet(zm,(unsigned char*) "age",3, (unsigned char*) "foo",3,NULL); in zipmapTest()
419 zipmapRepr(zm); in zipmapTest()
421 zm = zipmapSet(zm,(unsigned char*) "hello",5, (unsigned char*) "world!",6,NULL); in zipmapTest()
422 zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "bar",3,NULL); in zipmapTest()
423 zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "!",1,NULL); in zipmapTest()
424 zipmapRepr(zm); in zipmapTest()
425 zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "12345",5,NULL); in zipmapTest()
426 zipmapRepr(zm); in zipmapTest()
427 zm = zipmapSet(zm,(unsigned char*) "new",3, (unsigned char*) "xx",2,NULL); in zipmapTest()
428 zm = zipmapSet(zm,(unsigned char*) "noval",5, (unsigned char*) "",0,NULL); in zipmapTest()
429 zipmapRepr(zm); in zipmapTest()
430 zm = zipmapDel(zm,(unsigned char*) "new",3,NULL); in zipmapTest()
431 zipmapRepr(zm); in zipmapTest()
440 zm = zipmapSet(zm,buf,512,(unsigned char*) "long",4,NULL); in zipmapTest()
441 if (zipmapGet(zm,buf,512,&value,&vlen)) { in zipmapTest()
452 if (zipmapGet(zm,(unsigned char*) "foo",3,&value,&vlen)) { in zipmapTest()
459 unsigned char *i = zipmapRewind(zm); in zipmapTest()