mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
added an union in the dict.h structure to store 64 bit integers directly into hash table entries.
This commit is contained in:
parent
ef23f3ac92
commit
6a7841eb09
@ -270,7 +270,7 @@ int dictAdd(dict *d, void *key, void *val)
|
|||||||
if ((index = _dictKeyIndex(d, key)) == -1)
|
if ((index = _dictKeyIndex(d, key)) == -1)
|
||||||
return DICT_ERR;
|
return DICT_ERR;
|
||||||
|
|
||||||
/* Allocates the memory and stores key */
|
/* Allocate the memory and store the new entry */
|
||||||
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
|
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
|
||||||
entry = zmalloc(sizeof(*entry));
|
entry = zmalloc(sizeof(*entry));
|
||||||
entry->next = ht->table[index];
|
entry->next = ht->table[index];
|
||||||
@ -297,7 +297,6 @@ int dictReplace(dict *d, void *key, void *val)
|
|||||||
return 1;
|
return 1;
|
||||||
/* It already exists, get the entry */
|
/* It already exists, get the entry */
|
||||||
entry = dictFind(d, key);
|
entry = dictFind(d, key);
|
||||||
/* Free the old value and set the new one */
|
|
||||||
/* Set the new value and free the old one. Note that it is important
|
/* Set the new value and free the old one. Note that it is important
|
||||||
* to do that in this order, as the value may just be exactly the same
|
* to do that in this order, as the value may just be exactly the same
|
||||||
* as the previous one. In this context, think to reference counting,
|
* as the previous one. In this context, think to reference counting,
|
||||||
|
16
src/dict.h
16
src/dict.h
@ -33,6 +33,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef __DICT_H
|
#ifndef __DICT_H
|
||||||
#define __DICT_H
|
#define __DICT_H
|
||||||
|
|
||||||
@ -44,7 +46,11 @@
|
|||||||
|
|
||||||
typedef struct dictEntry {
|
typedef struct dictEntry {
|
||||||
void *key;
|
void *key;
|
||||||
void *val;
|
union {
|
||||||
|
void *val;
|
||||||
|
uint64_t u64;
|
||||||
|
int64_t i64;
|
||||||
|
} v;
|
||||||
struct dictEntry *next;
|
struct dictEntry *next;
|
||||||
} dictEntry;
|
} dictEntry;
|
||||||
|
|
||||||
@ -90,13 +96,13 @@ typedef struct dictIterator {
|
|||||||
/* ------------------------------- Macros ------------------------------------*/
|
/* ------------------------------- Macros ------------------------------------*/
|
||||||
#define dictFreeEntryVal(d, entry) \
|
#define dictFreeEntryVal(d, entry) \
|
||||||
if ((d)->type->valDestructor) \
|
if ((d)->type->valDestructor) \
|
||||||
(d)->type->valDestructor((d)->privdata, (entry)->val)
|
(d)->type->valDestructor((d)->privdata, (entry)->v.val)
|
||||||
|
|
||||||
#define dictSetHashVal(d, entry, _val_) do { \
|
#define dictSetHashVal(d, entry, _val_) do { \
|
||||||
if ((d)->type->valDup) \
|
if ((d)->type->valDup) \
|
||||||
entry->val = (d)->type->valDup((d)->privdata, _val_); \
|
entry->v.val = (d)->type->valDup((d)->privdata, _val_); \
|
||||||
else \
|
else \
|
||||||
entry->val = (_val_); \
|
entry->v.val = (_val_); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define dictFreeEntryKey(d, entry) \
|
#define dictFreeEntryKey(d, entry) \
|
||||||
@ -118,7 +124,7 @@ typedef struct dictIterator {
|
|||||||
#define dictHashKey(d, key) (d)->type->hashFunction(key)
|
#define dictHashKey(d, key) (d)->type->hashFunction(key)
|
||||||
|
|
||||||
#define dictGetEntryKey(he) ((he)->key)
|
#define dictGetEntryKey(he) ((he)->key)
|
||||||
#define dictGetEntryVal(he) ((he)->val)
|
#define dictGetEntryVal(he) ((he)->v.val)
|
||||||
#define dictSlots(d) ((d)->ht[0].size+(d)->ht[1].size)
|
#define dictSlots(d) ((d)->ht[0].size+(d)->ht[1].size)
|
||||||
#define dictSize(d) ((d)->ht[0].used+(d)->ht[1].used)
|
#define dictSize(d) ((d)->ht[0].used+(d)->ht[1].used)
|
||||||
#define dictIsRehashing(ht) ((ht)->rehashidx != -1)
|
#define dictIsRehashing(ht) ((ht)->rehashidx != -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user