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. */
| 241 | * to a hash table) is presized to hold the number of elements in the original |
| 242 | * set. */ |
| 243 | void 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 |
no test coverage detected