summaryrefslogtreecommitdiff
path: root/src/dict.h
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-11-02 15:28:45 +0100
committerantirez <antirez@gmail.com>2011-11-02 15:28:45 +0100
commit6a7841eb099e8f92bb2c321e87e2b1f4724ddaed (patch)
treebcae4cc92c277cfe0c18c542bdda24fc25851a69 /src/dict.h
parentef23f3ac920c4cc1f403a2765455e455b03101bd (diff)
downloadredis-6a7841eb099e8f92bb2c321e87e2b1f4724ddaed.tar.gz
added an union in the dict.h structure to store 64 bit integers directly into hash table entries.
Diffstat (limited to 'src/dict.h')
-rw-r--r--src/dict.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/dict.h b/src/dict.h
index 74bcd2aad..31cd65646 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -33,6 +33,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdint.h>
+
#ifndef __DICT_H
#define __DICT_H
@@ -44,7 +46,11 @@
typedef struct dictEntry {
void *key;
- void *val;
+ union {
+ void *val;
+ uint64_t u64;
+ int64_t i64;
+ } v;
struct dictEntry *next;
} dictEntry;
@@ -90,13 +96,13 @@ typedef struct dictIterator {
/* ------------------------------- Macros ------------------------------------*/
#define dictFreeEntryVal(d, entry) \
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 { \
if ((d)->type->valDup) \
- entry->val = (d)->type->valDup((d)->privdata, _val_); \
+ entry->v.val = (d)->type->valDup((d)->privdata, _val_); \
else \
- entry->val = (_val_); \
+ entry->v.val = (_val_); \
} while(0)
#define dictFreeEntryKey(d, entry) \
@@ -118,7 +124,7 @@ typedef struct dictIterator {
#define dictHashKey(d, key) (d)->type->hashFunction(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 dictSize(d) ((d)->ht[0].used+(d)->ht[1].used)
#define dictIsRehashing(ht) ((ht)->rehashidx != -1)