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

Function zzlLastInRange

src/t_zset.cpp:883–912  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

881/* Find pointer to the last element contained in the specified range.
882 * Returns NULL when no element is contained in the range. */
883unsigned char *zzlLastInRange(unsigned char *zl, zrangespec *range) {
884 unsigned char *eptr = ziplistIndex(zl,-2), *sptr;
885 double score;
886
887 /* If everything is out of range, return early. */
888 if (!zzlIsInRange(zl,range)) return NULL;
889
890 while (eptr != NULL) {
891 sptr = ziplistNext(zl,eptr);
892 serverAssert(sptr != NULL);
893
894 score = zzlGetScore(sptr);
895 if (zslValueLteMax(score,range)) {
896 /* Check if score >= min. */
897 if (zslValueGteMin(score,range))
898 return eptr;
899 return NULL;
900 }
901
902 /* Move to previous element by moving to the score of previous element.
903 * When this returns NULL, we know there also is no element. */
904 sptr = ziplistPrev(zl,eptr);
905 if (sptr != NULL)
906 serverAssert((eptr = ziplistPrev(zl,sptr)) != NULL);
907 else
908 eptr = NULL;
909 }
910
911 return NULL;
912}
913
914int zzlLexValueGteMin(unsigned char *p, zlexrangespec *spec) {
915 sds value = ziplistGetObject(p);

Callers 2

zsetInitScoreRangeFunction · 0.85

Calls 7

ziplistIndexFunction · 0.85
zzlIsInRangeFunction · 0.85
ziplistNextFunction · 0.85
zzlGetScoreFunction · 0.85
zslValueLteMaxFunction · 0.85
zslValueGteMinFunction · 0.85
ziplistPrevFunction · 0.85

Tested by

no test coverage detected