typedef struct Dictentry {void *key; Union {void *val; uint64_t U64; int64_t S64; Double D; } V; struct Dictentry *next;} Dictentry;
typedef struct DICTHT {dictentry **table; unsigned long size; Dictionary size unsigned long sizemask; unsigned long used;} dictht;
typedef struct DICT {Dicttype *type; void *privdata; Dictht ht[2]; Rehash, from old to new long rehashidx; /* rehashing not in progress if rehashidx = = 1 */int iterators; /* Number of iterators currently running */} dict;
put safe 1 to define the iterator as safe, i.e. add, The lookup or other operation is with the other iterator exclusive.
/* if safe is set to 1 this is a safe iterator, that means, you can call * dictAdd, dictFind, and other functions against the dictionary Even while * iterating. otherwise it is a non safe iterator, and only dictnext () * should be called while iterating. */ Typedef struct dictiterator { dict *d; long index; int table, safe; dictentry *entry, *nextentry; /* unsafe iterator fingerprint for misuse detection. */ long long fingerprint;} dictiterator;
The method of using fingerprints when designing iterators (Long Long dictfingerprint (dict *d))
When you apply for an iterator, a hash value is calculated based on the address, size, and usage of the current dictionary. Each time an iterator is used, the fingerprint of the iterator is compared
This iterator is not available if it is different from the current dictionary's thumbprint.
On the rehash of the dictionary
A dictionary is essentially a hash table. The rehash strategy for Redis is to record the location of each rehash each time
The operation of the dictionary is judged whether the rehash operation is in progress. If it is rehash, it takes too long to avoid an operation
Defines the maximum number of buckets for a single operation
Redis Dictionary data structure