MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / zipmapLookupRaw

Function zipmapLookupRaw

src/zipmap.c:142–170  ·  view source on GitHub ↗

Search for a matching key, returning a pointer to the entry inside the * zipmap. Returns NULL if the key is not found. * * If NULL is returned, and totlen is not NULL, it is set to the entire * size of the zipmap, so that the calling function will be able to * reallocate the original zipmap to make room for more entries. */

Source from the content-addressed store, hash-verified

140 * size of the zipmap, so that the calling function will be able to
141 * reallocate the original zipmap to make room for more entries. */
142static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, unsigned int klen, unsigned int *totlen) {
143 unsigned char *p = zm+1, *k = NULL;
144 unsigned int l,llen;
145
146 while(*p != ZIPMAP_END) {
147 unsigned char free;
148
149 /* Match or skip the key */
150 l = zipmapDecodeLength(p);
151 llen = zipmapEncodeLength(NULL,l);
152 if (key != NULL && k == NULL && l == klen && !memcmp(p+llen,key,l)) {
153 /* Only return when the user doesn't care
154 * for the total length of the zipmap. */
155 if (totlen != NULL) {
156 k = p;
157 } else {
158 return p;
159 }
160 }
161 p += llen+l;
162 /* Skip the value as well */
163 l = zipmapDecodeLength(p);
164 p += zipmapEncodeLength(NULL,l);
165 free = p[0];
166 p += l+1+free; /* +1 to skip the free byte */
167 }
168 if (totlen != NULL) *totlen = (unsigned int)(p-zm)+1;
169 return k;
170}
171
172static unsigned long zipmapRequiredLength(unsigned int klen, unsigned int vlen) {
173 unsigned int l;

Callers 5

zipmapSetFunction · 0.85
zipmapDelFunction · 0.85
zipmapGetFunction · 0.85
zipmapExistsFunction · 0.85
zipmapBlobLenFunction · 0.85

Calls 2

zipmapDecodeLengthFunction · 0.85
zipmapEncodeLengthFunction · 0.85

Tested by

no test coverage detected