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

Function zuiNext

src/t_zset.cpp:2164–2222  ·  view source on GitHub ↗

Check if the current value is valid. If so, store it in the passed structure * and move to the next element. If not valid, this means we have reached the * end of the structure and can abort. */

Source from the content-addressed store, hash-verified

2162 * and move to the next element. If not valid, this means we have reached the
2163 * end of the structure and can abort. */
2164int zuiNext(zsetopsrc *op, zsetopval *val) {
2165 if (op->subject == NULL)
2166 return 0;
2167
2168 if (val->flags & OPVAL_DIRTY_SDS)
2169 sdsfree(val->ele);
2170
2171 memset(val,0,sizeof(zsetopval));
2172
2173 if (op->type == OBJ_SET) {
2174 iterset *it = &op->iter.set;
2175 if (op->encoding == OBJ_ENCODING_INTSET) {
2176 int64_t ell;
2177
2178 if (!intsetGet(it->is.is,it->is.ii,&ell))
2179 return 0;
2180 val->ell = ell;
2181 val->score = 1.0;
2182
2183 /* Move to next element. */
2184 it->is.ii++;
2185 } else if (op->encoding == OBJ_ENCODING_HT) {
2186 if (it->ht.de == NULL)
2187 return 0;
2188 val->ele = (sds)dictGetKey(it->ht.de);
2189 val->score = 1.0;
2190
2191 /* Move to next element. */
2192 it->ht.de = dictNext(it->ht.di);
2193 } else {
2194 serverPanic("Unknown set encoding");
2195 }
2196 } else if (op->type == OBJ_ZSET) {
2197 iterzset *it = &op->iter.iterzset;
2198 if (op->encoding == OBJ_ENCODING_ZIPLIST) {
2199 /* No need to check both, but better be explicit. */
2200 if (it->zl.eptr == NULL || it->zl.sptr == NULL)
2201 return 0;
2202 serverAssert(ziplistGet(it->zl.eptr,&val->estr,&val->elen,&val->ell));
2203 val->score = zzlGetScore(it->zl.sptr);
2204
2205 /* Move to next element (going backwards, see zuiInitIterator). */
2206 zzlPrev(it->zl.zl,&it->zl.eptr,&it->zl.sptr);
2207 } else if (op->encoding == OBJ_ENCODING_SKIPLIST) {
2208 if (it->sl.node == NULL)
2209 return 0;
2210 val->ele = it->sl.node->ele;
2211 val->score = it->sl.node->score;
2212
2213 /* Move to next element. (going backwards, see zuiInitIterator) */
2214 it->sl.node = it->sl.node->backward;
2215 } else {
2216 serverPanic("Unknown sorted set encoding");
2217 }
2218 } else {
2219 serverPanic("Unsupported type");
2220 }
2221 return 1;

Callers 4

zdiffAlgorithm1Function · 0.85
zdiffAlgorithm2Function · 0.85

Calls 6

sdsfreeFunction · 0.85
intsetGetFunction · 0.85
ziplistGetFunction · 0.85
zzlGetScoreFunction · 0.85
zzlPrevFunction · 0.85
dictNextFunction · 0.70

Tested by

no test coverage detected