Usage of dict in redis and redisdict

Source: Internet
Author: User

Usage of dict in redis and redisdict

Usage of dict in redis

Redis uses dict to represent a dictionary typedef struct dict {// similar to sds, define a set of function pointers dictType * type; // Private Data void * privdata; // hash table dictht ht [2]; // when no rehash operation is performed, the value is-1 int rehashidx; /* rehashing not in progress if rehashidx =-1 * // number of iterators int iterators;/* number of iterators currently running */} dict; this dict has two important data structures: 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; this dictType defines six function pointers. The meanings of these function pointers are clear. The second is: Hash table typedef struct dictht {// hash table array dictEntry ** table; unsigned long size; // always equal to size-1 unsigned long sizemask; // number of existing nodes in the hash table unsigned long used;} dictht; The table indicates the array of the hash table, the Data Types of a single node are defined as follows: typedef struct dictEntry {// key void * key; // you can see that the hash table can store three types of data types: union {void * val; uint64_t u64; int64_t s64;} v; // points to the next hash table node to form the chain table struct dictEntry * next;} dictEntry; call dictCreate to create a new dictionary, it seems that when creating a dict, six function pointers and private data dict * dictCreate (dictType * type, void * privDataPtr) must be created) {# apply for memory and clear dict * d = zmalloc (sizeof (* d); _ dictInit (d, type, privDataPtr); return d ;} int _ dictInit (dict * d, dictType * type, void * privDataPtr) {// specify the initial value _ dictReset (& d-> ht [0]) for two hash tables; _ dictReset (& d-> ht [1]); // assign the initial value or default value d-> type = type; d-> privdata = privDataPtr to the member variable based on the parameter; d-> rehashidx =-1; d-> iterators = 0; return DICT_ OK;} // assign the initial value static void _ dictReset (dictht * ht) to the two hash tables) {ht-> table = NULL; ht-> size = 0; ht-> sizemask = 0; ht-> used = 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.