@@ -1079,50 +1079,50 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1079
1079
* used into CASE 4 is highly inefficient. */
1080
1080
if (count * HRANDFIELD_SUB_STRATEGY_MUL > size ) {
1081
1081
/* Hashtable encoding (generic implementation) */
1082
- dict * d = dictCreate ( & sdsReplyDictType );
1083
- dictExpand ( d , size );
1082
+ hashtable * ht = hashtableCreate ( & hashHashtableType );
1083
+ hashtableExpand ( ht , size );
1084
1084
hashTypeIterator hi ;
1085
1085
hashTypeInitIterator (hash , & hi );
1086
1086
1087
- /* Add all the elements into the temporary dictionary . */
1088
- while (( hashTypeNext (& hi ) ) != C_ERR ) {
1089
- int ret = DICT_ERR ;
1087
+ /* Add all the elements into the temporary hashtable . */
1088
+ while (hashTypeNext (& hi ) != C_ERR ) {
1089
+ int ret = 0 ;
1090
1090
sds field , value = NULL ;
1091
1091
1092
1092
field = hashTypeCurrentObjectNewSds (& hi , OBJ_HASH_FIELD );
1093
1093
if (withvalues ) value = hashTypeCurrentObjectNewSds (& hi , OBJ_HASH_VALUE );
1094
- ret = dictAdd (d , field , value );
1095
-
1096
- serverAssert (ret == DICT_OK );
1094
+ hashTypeEntry * entry = hashTypeCreateEntry (field , value );
1095
+ sdsfree (field );
1096
+ ret = hashtableAdd (ht , entry );
1097
+ serverAssert (ret );
1097
1098
}
1098
- serverAssert (dictSize ( d ) == size );
1099
+ serverAssert (hashtableSize ( ht ) == size );
1099
1100
hashTypeResetIterator (& hi );
1100
1101
1101
1102
/* Remove random elements to reach the right count. */
1102
1103
while (size > count ) {
1103
- dictEntry * de ;
1104
- de = dictGetFairRandomKey (d );
1105
- dictUnlink (d , dictGetKey (de ));
1106
- sdsfree (dictGetKey (de ));
1107
- sdsfree (dictGetVal (de ));
1108
- dictFreeUnlinkedEntry (d , de );
1104
+ void * element ;
1105
+ hashtableFairRandomEntry (ht , & element );
1106
+ sds field = hashTypeEntryGetField ((hashTypeEntry * )element );
1107
+ hashtableDelete (ht , field );
1109
1108
size -- ;
1110
1109
}
1111
1110
1112
- /* Reply with what's in the dict and release memory */
1113
- dictIterator * di ;
1114
- dictEntry * de ;
1115
- di = dictGetIterator (d );
1116
- while ((de = dictNext (di )) != NULL ) {
1117
- sds field = dictGetKey (de );
1118
- sds value = dictGetVal (de );
1111
+ /* Reply with what's in the temporary hashtable and release memory */
1112
+ hashtableIterator iter ;
1113
+ hashtableInitIterator (& iter , ht , 0 );
1114
+ void * next ;
1115
+ while (hashtableNext (& iter , & next )) {
1116
+ hashTypeEntry * entry = (hashTypeEntry * )next ;
1117
+ sds field = hashTypeEntryGetField (entry );
1118
+ sds value = hashTypeEntryGetValue (entry );
1119
1119
if (withvalues && c -> resp > 2 ) addWritePreparedReplyArrayLen (wpc , 2 );
1120
- addWritePreparedReplyBulkSds (wpc , field );
1121
- if (withvalues ) addWritePreparedReplyBulkSds (wpc , value );
1120
+ addWritePreparedReplyBulkSds (wpc , sdsdup ( field ) );
1121
+ if (withvalues ) addWritePreparedReplyBulkSds (wpc , sdsdup ( value ) );
1122
1122
}
1123
-
1124
- dictReleaseIterator ( di );
1125
- dictRelease ( d );
1123
+
1124
+ hashtableResetIterator ( & iter );
1125
+ hashtableRelease ( ht );
1126
1126
}
1127
1127
1128
1128
/* CASE 4: We have a big hash compared to the requested number of elements.
@@ -1133,16 +1133,16 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1133
1133
/* Hashtable encoding (generic implementation) */
1134
1134
unsigned long added = 0 ;
1135
1135
listpackEntry field , value ;
1136
- dict * d = dictCreate ( & hashDictType );
1137
- dictExpand ( d , count );
1136
+ hashtable * ht = hashtableCreate ( & setHashtableType );
1137
+ hashtableExpand ( ht , count );
1138
1138
while (added < count ) {
1139
1139
hashTypeRandomElement (hash , size , & field , withvalues ? & value : NULL );
1140
1140
1141
- /* Try to add the object to the dictionary . If it already exists
1141
+ /* Try to add the object to the hashtable . If it already exists
1142
1142
* free it, otherwise increment the number of objects we have
1143
- * in the result dictionary . */
1143
+ * in the result hashtable . */
1144
1144
sds sfield = hashSdsFromListpackEntry (& field );
1145
- if (dictAdd ( d , sfield , NULL ) != DICT_OK ) {
1145
+ if (! hashtableAdd ( ht , sfield ) ) {
1146
1146
sdsfree (sfield );
1147
1147
continue ;
1148
1148
}
@@ -1155,7 +1155,7 @@ void hrandfieldWithCountCommand(client *c, long l, int withvalues) {
1155
1155
}
1156
1156
1157
1157
/* Release memory */
1158
- dictRelease ( d );
1158
+ hashtableRelease ( ht );
1159
1159
}
1160
1160
}
1161
1161
0 commit comments