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

Function zzlDeleteRangeByScore

src/t_zset.cpp:1092–1119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1090}
1091
1092unsigned char *zzlDeleteRangeByScore(unsigned char *zl, zrangespec *range, unsigned long *deleted) {
1093 unsigned char *eptr, *sptr;
1094 double score;
1095 unsigned long num = 0;
1096
1097 if (deleted != NULL) *deleted = 0;
1098
1099 eptr = zzlFirstInRange(zl,range);
1100 if (eptr == NULL) return zl;
1101
1102 /* When the tail of the ziplist is deleted, eptr will point to the sentinel
1103 * byte and ziplistNext will return NULL. */
1104 while ((sptr = ziplistNext(zl,eptr)) != NULL) {
1105 score = zzlGetScore(sptr);
1106 if (zslValueLteMax(score,range)) {
1107 /* Delete both the element and the score. */
1108 zl = ziplistDelete(zl,&eptr);
1109 zl = ziplistDelete(zl,&eptr);
1110 num++;
1111 } else {
1112 /* No longer in range. */
1113 break;
1114 }
1115 }
1116
1117 if (deleted != NULL) *deleted = num;
1118 return zl;
1119}
1120
1121unsigned char *zzlDeleteRangeByLex(unsigned char *zl, zlexrangespec *range, unsigned long *deleted) {
1122 unsigned char *eptr, *sptr;

Callers 1

zremrangeGenericCommandFunction · 0.85

Calls 5

zzlFirstInRangeFunction · 0.85
ziplistNextFunction · 0.85
zzlGetScoreFunction · 0.85
zslValueLteMaxFunction · 0.85
ziplistDeleteFunction · 0.85

Tested by

no test coverage detected