X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/c0ba9ebe13865189a3b21f7be8a910e349b59fda..4ce22375f45e7e1a6f9c9548fe47613b61242e48:/src/dict.c?ds=inline diff --git a/src/dict.c b/src/dict.c index 11962f7c..6fd4584e 100644 --- a/src/dict.c +++ b/src/dict.c @@ -85,10 +85,20 @@ unsigned int dictIdentityHashFunction(unsigned int key) return key; } +static int dict_hash_function_seed = 5381; + +void dictSetHashFunctionSeed(unsigned int seed) { + dict_hash_function_seed = seed; +} + +unsigned int dictGetHashFunctionSeed(void) { + return dict_hash_function_seed; +} + /* Generic hash function (a popular one from Bernstein). * I tested a few and this was the best. */ unsigned int dictGenHashFunction(const unsigned char *buf, int len) { - unsigned int hash = 5381; + unsigned int hash = dict_hash_function_seed; while (len--) hash = ((hash << 5) + hash) + (*buf++); /* hash * 33 + c */ @@ -97,7 +107,7 @@ unsigned int dictGenHashFunction(const unsigned char *buf, int len) { /* And a case insensitive version */ unsigned int dictGenCaseHashFunction(const unsigned char *buf, int len) { - unsigned int hash = 5381; + unsigned int hash = dict_hash_function_seed; while (len--) hash = ((hash << 5) + hash) + (tolower(*buf++)); /* hash * 33 + c */ @@ -140,7 +150,7 @@ int _dictInit(dict *d, dictType *type, } /* Resize the table to the minimal size that contains all the elements, - * but with the invariant of a USER/BUCKETS ratio near to <= 1 */ + * but with the invariant of a USED/BUCKETS ratio near to <= 1 */ int dictResize(dict *d) { int minimal; @@ -274,7 +284,7 @@ int dictAdd(dict *d, void *key, void *val) * mainly in order to store non-pointers inside the hash value, example: * * entry = dictAddRaw(dict,mykey); - * if (entry != NULL) dictSetValSignedInteger(entry,1000); + * if (entry != NULL) dictSetSignedIntegerVal(entry,1000); * * Return values: *