redis源碼閱讀筆記----dict.c
阿新 • • 發佈:2017-11-12
redis cte num const redis源碼 light str vda table
dict是redis中的基本數據結構,源碼中是通過hash表來實現的。項目將挑選幾個主要函數和大家分享下redis源碼的簡潔。
先看dict的數據結構如下
typedef struct dictType { unsigned int (*hashFunction)(const void *key); void *(*keyDup)(void *privdata, const void *key); void *(*valDup)(void *privdata, const void *obj); int (*keyCompare)(void *privdata, const void *key1, const void *key2); void (*keyDestructor)(void *privdata, void *key); void (*valDestructor)(void *privdata, void *obj); } dictType;
typedef struct dictht { dictEntry **table; unsigned long size; unsigned long sizemask; unsigned long used; } dictht;
typedef struct dict { dictType *type; void *privdata; dictht ht[2]; long rehashidx; /* rehashing not in progress if rehashidx == -1 */ unsigned long iterators; /* number of iterators currently running */ } dict;
type是hash表的內置函數,包括計算hash key,比較hash key等等。
ht[2]中的每個元素表示一張hash表。
redis源碼閱讀筆記----dict.c