MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lpLength

Function lpLength

app/redis-6.2.6/src/listpack.c:498–515  ·  view source on GitHub ↗

Return the number of elements inside the listpack. This function attempts * to use the cached value when within range, otherwise a full scan is * needed. As a side effect of calling this function, the listpack header * could be modified, because if the count is found to be already within * the 'numele' header field range, the new value is set. */

Source from the content-addressed store, hash-verified

496 * could be modified, because if the count is found to be already within
497 * the 'numele' header field range, the new value is set. */
498uint32_t lpLength(unsigned char *lp) {
499 uint32_t numele = lpGetNumElements(lp);
500 if (numele != LP_HDR_NUMELE_UNKNOWN) return numele;
501
502 /* Too many elements inside the listpack. We need to scan in order
503 * to get the total number. */
504 uint32_t count = 0;
505 unsigned char *p = lpFirst(lp);
506 while(p) {
507 count++;
508 p = lpNext(lp,p);
509 }
510
511 /* If the count is again within range of the header numele field,
512 * set it. */
513 if (count < LP_HDR_NUMELE_UNKNOWN) lpSetNumElements(lp,count);
514 return count;
515}
516
517/* Return the listpack element pointed by 'p'.
518 *

Callers

nothing calls this directly

Calls 2

lpFirstFunction · 0.85
lpNextFunction · 0.85

Tested by

no test coverage detected