Move dict to C++

Former-commit-id: b50acd7238db7dc0935cd304070476f63ffff3f0
This commit is contained in:
John Sully 2019-04-07 17:23:59 -04:00
parent ad361c2aa8
commit e766f66b11
3 changed files with 17 additions and 9 deletions

View File

@ -270,7 +270,7 @@ $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
dict-benchmark: dict.c zmalloc.c sds.c siphash.c
dict-benchmark: dict.cpp zmalloc.c sds.c siphash.c
$(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS)
# Because the jemalloc.h header is generated as a part of the jemalloc build,

View File

@ -84,11 +84,11 @@ uint8_t *dictGetHashFunctionSeed(void) {
/* The default hashing function uses SipHash implementation
* in siphash.c. */
uint64_t siphash(const uint8_t *in, const size_t inlen, const uint8_t *k);
uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k);
extern "C" uint64_t siphash(const uint8_t *in, const size_t inlen, const uint8_t *k);
extern "C" uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k);
uint64_t dictGenHashFunction(const void *key, int len) {
return siphash(key,len,dict_hash_function_seed);
return siphash((const uint8_t*)key,len,dict_hash_function_seed);
}
uint64_t dictGenCaseHashFunction(const unsigned char *buf, int len) {
@ -111,7 +111,7 @@ static void _dictReset(dictht *ht)
dict *dictCreate(dictType *type,
void *privDataPtr)
{
dict *d = zmalloc(sizeof(*d), MALLOC_SHARED);
dict *d = (dict*)zmalloc(sizeof(*d), MALLOC_SHARED);
_dictInit(d,type,privDataPtr);
return d;
@ -160,7 +160,7 @@ int dictExpand(dict *d, unsigned long size)
/* Allocate the new hash table and initialize all pointers to NULL */
n.size = realsize;
n.sizemask = realsize-1;
n.table = zcalloc(realsize*sizeof(dictEntry*), MALLOC_SHARED);
n.table = (dictEntry**)zcalloc(realsize*sizeof(dictEntry*), MALLOC_SHARED);
n.used = 0;
/* Is this the first initialization? If so it's not really a rehashing
@ -307,7 +307,7 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
* system it is more likely that recently added entries are accessed
* more frequently. */
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
entry = zmalloc(sizeof(*entry), MALLOC_SHARED);
entry = (dictEntry*)zmalloc(sizeof(*entry), MALLOC_SHARED);
entry->next = ht->table[index];
ht->table[index] = entry;
ht->used++;
@ -541,7 +541,7 @@ long long dictFingerprint(dict *d) {
dictIterator *dictGetIterator(dict *d)
{
dictIterator *iter = zmalloc(sizeof(*iter), MALLOC_LOCAL);
dictIterator *iter = (dictIterator*)zmalloc(sizeof(*iter), MALLOC_LOCAL);
iter->d = d;
iter->table = 0;

View File

@ -40,10 +40,18 @@
#include <unistd.h> /* for _exit() */
#ifdef __cplusplus
extern "C" {
#endif
#define assert(_e) ((_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),_exit(1)))
#define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),_exit(1)
void _serverAssert(char *estr, char *file, int line);
void _serverAssert(const char *estr, const char *file, int line);
void _serverPanic(const char *file, int line, const char *msg, ...);
#ifdef __cplusplus
}
#endif
#endif