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

Function zuiFind

src/t_zset.cpp:2287–2338  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

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

Callers 2

zdiffAlgorithm1Function · 0.85

Calls 5

zuiLongLongFromValueFunction · 0.85
intsetFindFunction · 0.85
zuiSdsFromValueFunction · 0.85
zzlFindFunction · 0.85
dictFindFunction · 0.70

Tested by

no test coverage detected