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

Function setTypeConvert

src/t_set.cpp:243–270  ·  view source on GitHub ↗

Convert the set to specified encoding. The resulting dict (when converting * to a hash table) is presized to hold the number of elements in the original * set. */

Source from the content-addressed store, hash-verified

241 * to a hash table) is presized to hold the number of elements in the original
242 * set. */
243void setTypeConvert(robj *setobj, int enc) {
244 setTypeIterator *si;
245 serverAssertWithInfo(NULL,setobj,setobj->type == OBJ_SET &&
246 setobj->encoding == OBJ_ENCODING_INTSET);
247
248 if (enc == OBJ_ENCODING_HT) {
249 int64_t intele;
250 dict *d = dictCreate(&setDictType,NULL);
251 const char *element;
252
253 /* Presize the dict to avoid rehashing */
254 dictExpand(d,intsetLen((intset*)setobj->m_ptr));
255
256 /* To add the elements we extract integers and create redis objects */
257 si = setTypeInitIterator(setobj);
258 while (setTypeNext(si,&element,&intele) != -1) {
259 sds elementNew = sdsfromlonglong(intele);
260 serverAssert(dictAdd(d,elementNew,NULL) == DICT_OK);
261 }
262 setTypeReleaseIterator(si);
263
264 setobj->encoding = OBJ_ENCODING_HT;
265 zfree(setobj->m_ptr);
266 setobj->m_ptr = d;
267 } else {
268 serverPanic("Unsupported set conversion");
269 }
270}
271
272/* This is a helper function for the COPY command.
273 * Duplicate a set object, with the guarantee that the returned object

Callers 2

rdbLoadObjectFunction · 0.85
setTypeAddFunction · 0.85

Calls 9

intsetLenFunction · 0.85
setTypeInitIteratorFunction · 0.85
setTypeNextFunction · 0.85
sdsfromlonglongFunction · 0.85
setTypeReleaseIteratorFunction · 0.85
zfreeFunction · 0.85
dictCreateFunction · 0.70
dictExpandFunction · 0.70
dictAddFunction · 0.70

Tested by

no test coverage detected