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

Function hashTypeNext

src/t_hash.cpp:351–384  ·  view source on GitHub ↗

Move to the next entry in the hash. Return C_OK when the next entry * could be found and C_ERR when the iterator reaches the end. */

Source from the content-addressed store, hash-verified

349/* Move to the next entry in the hash. Return C_OK when the next entry
350 * could be found and C_ERR when the iterator reaches the end. */
351int hashTypeNext(hashTypeIterator *hi) {
352 if (hi->encoding == OBJ_ENCODING_ZIPLIST) {
353 unsigned char *zl;
354 unsigned char *fptr, *vptr;
355
356 zl = (unsigned char*)hi->subject->m_ptr;
357 fptr = hi->fptr;
358 vptr = hi->vptr;
359
360 if (fptr == NULL) {
361 /* Initialize cursor */
362 serverAssert(vptr == NULL);
363 fptr = ziplistIndex(zl, 0);
364 } else {
365 /* Advance cursor */
366 serverAssert(vptr != NULL);
367 fptr = ziplistNext(zl, vptr);
368 }
369 if (fptr == NULL) return C_ERR;
370
371 /* Grab pointer to the value (fptr points to the field) */
372 vptr = ziplistNext(zl, fptr);
373 serverAssert(vptr != NULL);
374
375 /* fptr, vptr now point to the first or next pair */
376 hi->fptr = fptr;
377 hi->vptr = vptr;
378 } else if (hi->encoding == OBJ_ENCODING_HT) {
379 if ((hi->de = dictNext(hi->di)) == NULL) return C_ERR;
380 } else {
381 serverPanic("Unknown hash encoding");
382 }
383 return C_OK;
384}
385
386/* Get the field or value at iterator cursor, for an iterator on a hash value
387 * encoded as a ziplist. Prototype is similar to `hashTypeGetFromZiplist`. */

Callers 6

hashTypeConvertZiplistFunction · 0.85
hashTypeDupFunction · 0.85
genericHgetallCommandFunction · 0.85
xorObjectDigestFunction · 0.85
rewriteHashObjectFunction · 0.85

Calls 3

ziplistIndexFunction · 0.85
ziplistNextFunction · 0.85
dictNextFunction · 0.70

Tested by

no test coverage detected