redisソース解読5
1861 ワード
次にハッシュオブジェクトの研究を続け、2つの内部符号化があります.
では、問題はまた来て、それぞれどんな条件の下でどのコードに対応しますか?
よく知っていますか?リストの優先構造もziplistですが、なぜですか?
以前ziplistについて解読しましたが、ディクショナリの実装を見てみましょう.ソースコードはdict.hです.
ハッシュアルゴリズム
転載先:https://juejin.im/post/5c89bcdf6fb9a049b7813de3
ziplist:
hashtable
では、問題はまた来て、それぞれどんな条件の下でどのコードに対応しますか?
hash-max-ziplist-entries (512), hash-max-ziplist-value (64 ),
ziplist , hashtable。
よく知っていますか?リストの優先構造もziplistですが、なぜですか?
!!!
以前ziplistについて解読しましたが、ディクショナリの実装を見てみましょう.ソースコードはdict.hです.
typedef struct dictht {
dictEntry **table; //
unsigned long size; //
unsigned long sizemask; // , ,=size-1
unsigned long used; //
} dictht;
typedef struct dictEntry {
void *key; //
//
union {
void *val;
uint64_t u64;
int64_t s64;
double d;
} v;
struct dictEntry *next; // ,
} dictEntry;
typedef struct dict {
dictType *type; //
void *privdata; // , type
dictht ht[2]; //
long rehashidx; //rehash
int iterators;
} dict;
:type privdata ;ht[1] rehashidx rehash 。
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;
:
ハッシュアルゴリズム
1、 hash :hash = dict->type->hashFunction(k0);
2、 :index = hash&dict->ht[0].sizemask
転載先:https://juejin.im/post/5c89bcdf6fb9a049b7813de3