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