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

Function zzlLastInLexRange

app/redis-6.2.6/src/t_zset.c:978–1002  ·  view source on GitHub ↗

Find pointer to the last element contained in the specified lex range. * Returns NULL when no element is contained in the range. */

Source from the content-addressed store, hash-verified

976/* Find pointer to the last element contained in the specified lex range.
977 * Returns NULL when no element is contained in the range. */
978unsigned char *zzlLastInLexRange(unsigned char *zl, zlexrangespec *range) {
979 unsigned char *eptr = ziplistIndex(zl,-2), *sptr;
980
981 /* If everything is out of range, return early. */
982 if (!zzlIsInLexRange(zl,range)) return NULL;
983
984 while (eptr != NULL) {
985 if (zzlLexValueLteMax(eptr,range)) {
986 /* Check if score >= min. */
987 if (zzlLexValueGteMin(eptr,range))
988 return eptr;
989 return NULL;
990 }
991
992 /* Move to previous element by moving to the score of previous element.
993 * When this returns NULL, we know there also is no element. */
994 sptr = ziplistPrev(zl,eptr);
995 if (sptr != NULL)
996 serverAssert((eptr = ziplistPrev(zl,sptr)) != NULL);
997 else
998 eptr = NULL;
999 }
1000
1001 return NULL;
1002}
1003
1004unsigned char *zzlFind(unsigned char *zl, sds ele, double *score) {
1005 unsigned char *eptr = ziplistIndex(zl,0), *sptr;

Callers 2

zsetInitLexRangeFunction · 0.85

Calls 5

ziplistIndexFunction · 0.85
zzlIsInLexRangeFunction · 0.85
zzlLexValueLteMaxFunction · 0.85
zzlLexValueGteMinFunction · 0.85
ziplistPrevFunction · 0.85

Tested by

no test coverage detected