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

Function zzlFirstInLexRange

src/t_zset.cpp:953–974  ·  view source on GitHub ↗

Find pointer to the first 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

951/* Find pointer to the first element contained in the specified lex range.
952 * Returns NULL when no element is contained in the range. */
953unsigned char *zzlFirstInLexRange(unsigned char *zl, zlexrangespec *range) {
954 unsigned char *eptr = ziplistIndex(zl,0), *sptr;
955
956 /* If everything is out of range, return early. */
957 if (!zzlIsInLexRange(zl,range)) return NULL;
958
959 while (eptr != NULL) {
960 if (zzlLexValueGteMin(eptr,range)) {
961 /* Check if score <= max. */
962 if (zzlLexValueLteMax(eptr,range))
963 return eptr;
964 return NULL;
965 }
966
967 /* Move to next element. */
968 sptr = ziplistNext(zl,eptr); /* This element score. Skip it. */
969 serverAssert(sptr != NULL);
970 eptr = ziplistNext(zl,sptr); /* Next element. */
971 }
972
973 return NULL;
974}
975
976/* Find pointer to the last element contained in the specified lex range.
977 * Returns NULL when no element is contained in the range. */

Callers 4

zzlDeleteRangeByLexFunction · 0.85
zlexcountCommandFunction · 0.85
zsetInitLexRangeFunction · 0.85

Calls 5

ziplistIndexFunction · 0.85
zzlIsInLexRangeFunction · 0.85
zzlLexValueGteMinFunction · 0.85
zzlLexValueLteMaxFunction · 0.85
ziplistNextFunction · 0.85

Tested by

no test coverage detected