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

Function zsetInitScoreRange

src/module.cpp:2861–2889  ·  view source on GitHub ↗

Helper function for RM_ZsetFirstInScoreRange() and RM_ZsetLastInScoreRange(). * Setup the sorted set iteration according to the specified score range * (see the functions calling it for more info). If 'first' is true the * first element in the range is used as a starting point for the iterator * otherwise the last. Return REDISMODULE_OK on success otherwise * REDISMODULE_ERR. */

Source from the content-addressed store, hash-verified

2859 * otherwise the last. Return REDISMODULE_OK on success otherwise
2860 * REDISMODULE_ERR. */
2861int zsetInitScoreRange(RedisModuleKey *key, double min, double max, int minex, int maxex, int first) {
2862 if (!key->value || key->value->type != OBJ_ZSET) return REDISMODULE_ERR;
2863
2864 RM_ZsetRangeStop(key);
2865 key->u.zset.type = REDISMODULE_ZSET_RANGE_SCORE;
2866 key->u.zset.er = 0;
2867
2868 /* Setup the range structure used by the sorted set core implementation
2869 * in order to seek at the specified element. */
2870 zrangespec *zrs = &key->u.zset.rs;
2871 zrs->min = min;
2872 zrs->max = max;
2873 zrs->minex = minex;
2874 zrs->maxex = maxex;
2875
2876 if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
2877 key->u.zset.current = first ? zzlFirstInRange((unsigned char*)ptrFromObj(key->value),zrs) :
2878 zzlLastInRange((unsigned char*)ptrFromObj(key->value),zrs);
2879 } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
2880 zset *zs = (zset*)ptrFromObj(key->value);
2881 zskiplist *zsl = zs->zsl;
2882 key->u.zset.current = first ? zslFirstInRange(zsl,zrs) :
2883 zslLastInRange(zsl,zrs);
2884 } else {
2885 serverPanic("Unsupported zset encoding");
2886 }
2887 if (key->u.zset.current == NULL) key->u.zset.er = 1;
2888 return REDISMODULE_OK;
2889}
2890
2891/* Setup a sorted set iterator seeking the first element in the specified
2892 * range. Returns REDISMODULE_OK if the iterator was correctly initialized

Callers 2

RM_ZsetFirstInScoreRangeFunction · 0.85
RM_ZsetLastInScoreRangeFunction · 0.85

Calls 6

RM_ZsetRangeStopFunction · 0.85
zzlFirstInRangeFunction · 0.85
ptrFromObjFunction · 0.85
zzlLastInRangeFunction · 0.85
zslFirstInRangeFunction · 0.85
zslLastInRangeFunction · 0.85

Tested by

no test coverage detected