标签:dup nbsp val 结构 obj typedef cti def blog
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表。
标签:dup nbsp val 结构 obj typedef cti def blog
原文地址:http://www.cnblogs.com/real-madrid/p/7822425.html