Find value pointed to by val in the source pointer to by op. When found, * return 1 and store its score in target. Return 0 otherwise. */
| 2286 | /* Find value pointed to by val in the source pointer to by op. When found, |
| 2287 | * return 1 and store its score in target. Return 0 otherwise. */ |
| 2288 | int zuiFind(zsetopsrc *op, zsetopval *val, double *score) { |
| 2289 | if (op->subject == NULL) |
| 2290 | return 0; |
| 2291 | |
| 2292 | if (op->type == OBJ_SET) { |
| 2293 | if (op->encoding == OBJ_ENCODING_INTSET) { |
| 2294 | if (zuiLongLongFromValue(val) && |
| 2295 | intsetFind(op->subject->ptr,val->ell)) |
| 2296 | { |
| 2297 | *score = 1.0; |
| 2298 | return 1; |
| 2299 | } else { |
| 2300 | return 0; |
| 2301 | } |
| 2302 | } else if (op->encoding == OBJ_ENCODING_HT) { |
| 2303 | dict *ht = op->subject->ptr; |
| 2304 | zuiSdsFromValue(val); |
| 2305 | if (dictFind(ht,val->ele) != NULL) { |
| 2306 | *score = 1.0; |
| 2307 | return 1; |
| 2308 | } else { |
| 2309 | return 0; |
| 2310 | } |
| 2311 | } else { |
| 2312 | serverPanic("Unknown set encoding"); |
| 2313 | } |
| 2314 | } else if (op->type == OBJ_ZSET) { |
| 2315 | zuiSdsFromValue(val); |
| 2316 | |
| 2317 | if (op->encoding == OBJ_ENCODING_ZIPLIST) { |
| 2318 | if (zzlFind(op->subject->ptr,val->ele,score) != NULL) { |
| 2319 | /* Score is already set by zzlFind. */ |
| 2320 | return 1; |
| 2321 | } else { |
| 2322 | return 0; |
| 2323 | } |
| 2324 | } else if (op->encoding == OBJ_ENCODING_SKIPLIST) { |
| 2325 | zset *zs = op->subject->ptr; |
| 2326 | dictEntry *de; |
| 2327 | if ((de = dictFind(zs->dict,val->ele)) != NULL) { |
| 2328 | *score = *(double*)dictGetVal(de); |
| 2329 | return 1; |
| 2330 | } else { |
| 2331 | return 0; |
| 2332 | } |
| 2333 | } else { |
| 2334 | serverPanic("Unknown sorted set encoding"); |
| 2335 | } |
| 2336 | } else { |
| 2337 | serverPanic("Unsupported type"); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | int zuiCompareByCardinality(const void *s1, const void *s2) { |
| 2342 | unsigned long first = zuiLength((zsetopsrc*)s1); |
no test coverage detected