@@ -1227,50 +1227,50 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1227
1227
* used into CASE 4 is highly inefficient. */
1228
1228
if (count * HRANDFIELD_SUB_STRATEGY_MUL > size ) {
1229
1229
/* Hashtable encoding (generic implementation) */
1230
- dict * d = dictCreate ( & sdsReplyDictType );
1231
- dictExpand ( d , size );
1230
+ hashtable * ht = hashtableCreate ( & hashHashtableType );
1231
+ hashtableExpand ( ht , size );
1232
1232
hashTypeIterator hi ;
1233
1233
hashTypeInitIterator (hash , & hi );
1234
1234
1235
- /* Add all the elements into the temporary dictionary . */
1236
- while (( hashTypeNext (& hi ) ) != C_ERR ) {
1237
- int ret = DICT_ERR ;
1235
+ /* Add all the elements into the temporary hashtable . */
1236
+ while (hashTypeNext (& hi ) != C_ERR ) {
1237
+ int ret = 0 ;
1238
1238
sds field , value = NULL ;
1239
1239
1240
1240
field = hashTypeCurrentObjectNewSds (& hi , OBJ_HASH_FIELD );
1241
1241
if (withvalues ) value = hashTypeCurrentObjectNewSds (& hi , OBJ_HASH_VALUE );
1242
- ret = dictAdd (d , field , value );
1243
-
1244
- serverAssert (ret == DICT_OK );
1242
+ hashTypeEntry * entry = hashTypeCreateEntry (field , value );
1243
+ sdsfree (field );
1244
+ ret = hashtableAdd (ht , entry );
1245
+ serverAssert (ret );
1245
1246
}
1246
- serverAssert (dictSize ( d ) == size );
1247
+ serverAssert (hashtableSize ( ht ) == size );
1247
1248
hashTypeResetIterator (& hi );
1248
1249
1249
1250
/* Remove random elements to reach the right count. */
1250
1251
while (size > count ) {
1251
- dictEntry * de ;
1252
- de = dictGetFairRandomKey (d );
1253
- dictUnlink (d , dictGetKey (de ));
1254
- sdsfree (dictGetKey (de ));
1255
- sdsfree (dictGetVal (de ));
1256
- dictFreeUnlinkedEntry (d , de );
1252
+ void * element ;
1253
+ hashtableFairRandomEntry (ht , & element );
1254
+ sds field = hashTypeEntryGetField ((hashTypeEntry * )element );
1255
+ hashtableDelete (ht , field );
1257
1256
size -- ;
1258
1257
}
1259
1258
1260
- /* Reply with what's in the dict and release memory */
1261
- dictIterator * di ;
1262
- dictEntry * de ;
1263
- di = dictGetIterator (d );
1264
- while ((de = dictNext (di )) != NULL ) {
1265
- sds field = dictGetKey (de );
1266
- sds value = dictGetVal (de );
1259
+ /* Reply with what's in the temporary hashtable and release memory */
1260
+ hashtableIterator iter ;
1261
+ hashtableInitIterator (& iter , ht , 0 );
1262
+ void * next ;
1263
+ while (hashtableNext (& iter , & next )) {
1264
+ hashTypeEntry * entry = (hashTypeEntry * )next ;
1265
+ sds field = hashTypeEntryGetField (entry );
1266
+ sds value = hashTypeEntryGetValue (entry );
1267
1267
if (withvalues && c -> resp > 2 ) addWritePreparedReplyArrayLen (wpc , 2 );
1268
- addWritePreparedReplyBulkSds (wpc , field );
1269
- if (withvalues ) addWritePreparedReplyBulkSds (wpc , value );
1268
+ addWritePreparedReplyBulkSds (wpc , sdsdup ( field ) );
1269
+ if (withvalues ) addWritePreparedReplyBulkSds (wpc , sdsdup ( value ) );
1270
1270
}
1271
-
1272
- dictReleaseIterator ( di );
1273
- dictRelease ( d );
1271
+
1272
+ hashtableResetIterator ( & iter );
1273
+ hashtableRelease ( ht );
1274
1274
}
1275
1275
1276
1276
/* CASE 4: We have a big hash compared to the requested number of elements.
@@ -1281,16 +1281,16 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1281
1281
/* Hashtable encoding (generic implementation) */
1282
1282
unsigned long added = 0 ;
1283
1283
listpackEntry field , value ;
1284
- dict * d = dictCreate ( & hashDictType );
1285
- dictExpand ( d , count );
1284
+ hashtable * ht = hashtableCreate ( & setHashtableType );
1285
+ hashtableExpand ( ht , count );
1286
1286
while (added < count ) {
1287
1287
hashTypeRandomElement (hash , size , & field , withvalues ? & value : NULL );
1288
1288
1289
- /* Try to add the object to the dictionary . If it already exists
1289
+ /* Try to add the object to the hashtable . If it already exists
1290
1290
* free it, otherwise increment the number of objects we have
1291
- * in the result dictionary . */
1291
+ * in the result hashtable . */
1292
1292
sds sfield = hashSdsFromListpackEntry (& field );
1293
- if (dictAdd ( d , sfield , NULL ) != DICT_OK ) {
1293
+ if (! hashtableAdd ( ht , sfield ) ) {
1294
1294
sdsfree (sfield );
1295
1295
continue ;
1296
1296
}
@@ -1303,7 +1303,7 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1303
1303
}
1304
1304
1305
1305
/* Release memory */
1306
- dictRelease ( d );
1306
+ hashtableRelease ( ht );
1307
1307
}
1308
1308
}
1309
1309
0 commit comments