Skip to content

Commit

Permalink
dict.c API names modified to be more coincise and consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Nov 8, 2011
1 parent 71a5095 commit c0ba9eb
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 81 deletions.
14 changes: 7 additions & 7 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ int rewriteAppendOnlyFile(char *filename) {
robj key, *o;
time_t expiretime;

keystr = dictGetEntryKey(de);
o = dictGetEntryVal(de);
keystr = dictGetKey(de);
o = dictGetVal(de);
initStaticStringObject(key,keystr);

expiretime = getExpire(db,&key);
Expand Down Expand Up @@ -511,7 +511,7 @@ int rewriteAppendOnlyFile(char *filename) {
dictIterator *di = dictGetIterator(o->ptr);
dictEntry *de;
while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
robj *eleobj = dictGetKey(de);
if (rioWrite(&aof,cmd,sizeof(cmd)-1) == 0) goto werr;
if (rioWriteBulkObject(&aof,&key) == 0) goto werr;
if (rioWriteBulkObject(&aof,eleobj) == 0) goto werr;
Expand Down Expand Up @@ -559,8 +559,8 @@ int rewriteAppendOnlyFile(char *filename) {
dictEntry *de;

while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
double *score = dictGetEntryVal(de);
robj *eleobj = dictGetKey(de);
double *score = dictGetVal(de);

if (rioWrite(&aof,cmd,sizeof(cmd)-1) == 0) goto werr;
if (rioWriteBulkObject(&aof,&key) == 0) goto werr;
Expand Down Expand Up @@ -593,8 +593,8 @@ int rewriteAppendOnlyFile(char *filename) {
dictEntry *de;

while((de = dictNext(di)) != NULL) {
robj *field = dictGetEntryKey(de);
robj *val = dictGetEntryVal(de);
robj *field = dictGetKey(de);
robj *val = dictGetVal(de);

if (rioWrite(&aof,cmd,sizeof(cmd)-1) == 0) goto werr;
if (rioWriteBulkObject(&aof,&key) == 0) goto werr;
Expand Down
14 changes: 7 additions & 7 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ clusterNode *clusterLookupNode(char *name) {
de = dictFind(server.cluster.nodes,s);
sdsfree(s);
if (de == NULL) return NULL;
return dictGetEntryVal(de);
return dictGetVal(de);
}

/* This is only used after the handshake. When we connect a given IP/PORT
Expand Down Expand Up @@ -793,7 +793,7 @@ void clusterBroadcastMessage(void *buf, size_t len) {

di = dictGetIterator(server.cluster.nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetEntryVal(de);
clusterNode *node = dictGetVal(de);

if (!node->link) continue;
if (node->flags & (REDIS_NODE_MYSELF|REDIS_NODE_NOADDR)) continue;
Expand Down Expand Up @@ -849,7 +849,7 @@ void clusterSendPing(clusterLink *link, int type) {
/* Populate the gossip fields */
while(freshnodes > 0 && gossipcount < 3) {
struct dictEntry *de = dictGetRandomKey(server.cluster.nodes);
clusterNode *this = dictGetEntryVal(de);
clusterNode *this = dictGetVal(de);
clusterMsgDataGossip *gossip;
int j;

Expand Down Expand Up @@ -970,7 +970,7 @@ void clusterCron(void) {
/* Check if we have disconnected nodes and reestablish the connection. */
di = dictGetIterator(server.cluster.nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetEntryVal(de);
clusterNode *node = dictGetVal(de);

if (node->flags & (REDIS_NODE_MYSELF|REDIS_NODE_NOADDR)) continue;
if (node->link == NULL) {
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void clusterCron(void) {
* the oldest ping_sent time */
for (j = 0; j < 5; j++) {
de = dictGetRandomKey(server.cluster.nodes);
clusterNode *this = dictGetEntryVal(de);
clusterNode *this = dictGetVal(de);

if (this->link == NULL) continue;
if (this->flags & (REDIS_NODE_MYSELF|REDIS_NODE_HANDSHAKE)) continue;
Expand All @@ -1022,7 +1022,7 @@ void clusterCron(void) {
/* Iterate nodes to check if we need to flag something as failing */
di = dictGetIterator(server.cluster.nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetEntryVal(de);
clusterNode *node = dictGetVal(de);
int delay;

if (node->flags &
Expand Down Expand Up @@ -1153,7 +1153,7 @@ sds clusterGenNodesDescription(void) {

di = dictGetIterator(server.cluster.nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetEntryVal(de);
clusterNode *node = dictGetVal(de);

/* Node coordinates */
ci = sdscatprintf(ci,"%.40s %s:%d ",
Expand Down
10 changes: 5 additions & 5 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void SlotToKeyDel(robj *key);
robj *lookupKey(redisDb *db, robj *key) {
dictEntry *de = dictFind(db->dict,key->ptr);
if (de) {
robj *val = dictGetEntryVal(de);
robj *val = dictGetVal(de);

/* Update the access time for the aging algorithm.
* Don't do it if we have a saving child, as this will trigger
Expand Down Expand Up @@ -130,7 +130,7 @@ robj *dbRandomKey(redisDb *db) {
de = dictGetRandomKey(db->dict);
if (de == NULL) return NULL;

key = dictGetEntryKey(de);
key = dictGetKey(de);
keyobj = createStringObject(key,sdslen(key));
if (dictFind(db->expires,key)) {
if (expireIfNeeded(db,keyobj)) {
Expand Down Expand Up @@ -282,7 +282,7 @@ void keysCommand(redisClient *c) {
di = dictGetIterator(c->db->dict);
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
while((de = dictNext(di)) != NULL) {
sds key = dictGetEntryKey(de);
sds key = dictGetKey(de);
robj *keyobj;

if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
Expand Down Expand Up @@ -438,7 +438,7 @@ void setExpire(redisDb *db, robj *key, time_t when) {
/* Reuse the sds from the main dict in the expire dict */
de = dictFind(db->dict,key->ptr);
redisAssertWithInfo(NULL,key,de != NULL);
dictReplace(db->expires,dictGetEntryKey(de),(void*)when);
dictReplace(db->expires,dictGetKey(de),(void*)when);
}

/* Return the expire time of the specified key, or -1 if no expire
Expand All @@ -453,7 +453,7 @@ time_t getExpire(redisDb *db, robj *key) {
/* The entry was found in the expire dict, this means it should also
* be present in the main dict (safety check). */
redisAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);
return (time_t) dictGetEntryVal(de);
return (time_t) dictGetVal(de);
}

/* Propagate expires into slaves and the AOF file.
Expand Down
10 changes: 5 additions & 5 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ void computeDatasetDigest(unsigned char *final) {
time_t expiretime;

memset(digest,0,20); /* This key-val digest */
key = dictGetEntryKey(de);
key = dictGetKey(de);
keyobj = createStringObject(key,sdslen(key));

mixDigest(digest,key,sdslen(key));

/* Make sure the key is loaded if VM is active */
o = dictGetEntryVal(de);
o = dictGetVal(de);

aux = htonl(o->type);
mixDigest(digest,&aux,sizeof(aux));
Expand Down Expand Up @@ -165,8 +165,8 @@ void computeDatasetDigest(unsigned char *final) {
dictEntry *de;

while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
double *score = dictGetEntryVal(de);
robj *eleobj = dictGetKey(de);
double *score = dictGetVal(de);

snprintf(buf,sizeof(buf),"%.17g",*score);
memset(eledigest,0,20);
Expand Down Expand Up @@ -244,7 +244,7 @@ void debugCommand(redisClient *c) {
addReply(c,shared.nokeyerr);
return;
}
val = dictGetEntryVal(de);
val = dictGetVal(de);
strenc = strEncoding(val->encoding);

addReplyStatusFormat(c,
Expand Down
24 changes: 12 additions & 12 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int dictAdd(dict *d, void *key, void *val)
dictEntry *entry = dictAddRaw(d,key);

if (!entry) return DICT_ERR;
dictSetHashVal(d, entry, val);
dictSetVal(d, entry, val);
return DICT_OK;
}

Expand Down Expand Up @@ -302,7 +302,7 @@ dictEntry *dictAddRaw(dict *d, void *key)
ht->used++;

/* Set the hash entry fields. */
dictSetHashKey(d, entry, key);
dictSetKey(d, entry, key);
return entry;
}

Expand All @@ -326,8 +326,8 @@ int dictReplace(dict *d, void *key, void *val)
* you want to increment (set), and then decrement (free), and not the
* reverse. */
auxentry = *entry;
dictSetHashVal(d, entry, val);
dictFreeEntryVal(d, &auxentry);
dictSetVal(d, entry, val);
dictFreeVal(d, &auxentry);
return 0;
}

Expand Down Expand Up @@ -359,15 +359,15 @@ static int dictGenericDelete(dict *d, const void *key, int nofree)
he = d->ht[table].table[idx];
prevHe = NULL;
while(he) {
if (dictCompareHashKeys(d, key, he->key)) {
if (dictCompareKeys(d, key, he->key)) {
/* Unlink the element from the list */
if (prevHe)
prevHe->next = he->next;
else
d->ht[table].table[idx] = he->next;
if (!nofree) {
dictFreeEntryKey(d, he);
dictFreeEntryVal(d, he);
dictFreeKey(d, he);
dictFreeVal(d, he);
}
zfree(he);
d->ht[table].used--;
Expand Down Expand Up @@ -401,8 +401,8 @@ int _dictClear(dict *d, dictht *ht)
if ((he = ht->table[i]) == NULL) continue;
while(he) {
nextHe = he->next;
dictFreeEntryKey(d, he);
dictFreeEntryVal(d, he);
dictFreeKey(d, he);
dictFreeVal(d, he);
zfree(he);
ht->used--;
he = nextHe;
Expand Down Expand Up @@ -435,7 +435,7 @@ dictEntry *dictFind(dict *d, const void *key)
idx = h & d->ht[table].sizemask;
he = d->ht[table].table[idx];
while(he) {
if (dictCompareHashKeys(d, key, he->key))
if (dictCompareKeys(d, key, he->key))
return he;
he = he->next;
}
Expand All @@ -448,7 +448,7 @@ void *dictFetchValue(dict *d, const void *key) {
dictEntry *he;

he = dictFind(d,key);
return he ? dictGetEntryVal(he) : NULL;
return he ? dictGetVal(he) : NULL;
}

dictIterator *dictGetIterator(dict *d)
Expand Down Expand Up @@ -607,7 +607,7 @@ static int _dictKeyIndex(dict *d, const void *key)
/* Search if this slot does not already contain the given key */
he = d->ht[table].table[idx];
while(he) {
if (dictCompareHashKeys(d, key, he->key))
if (dictCompareKeys(d, key, he->key))
return -1;
he = he->next;
}
Expand Down
15 changes: 7 additions & 8 deletions src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,36 @@ typedef struct dictIterator {
#define DICT_HT_INITIAL_SIZE 4

/* ------------------------------- Macros ------------------------------------*/
#define dictFreeEntryVal(d, entry) \
#define dictFreeVal(d, entry) \
if ((d)->type->valDestructor) \
(d)->type->valDestructor((d)->privdata, (entry)->v.val)

#define dictSetHashVal(d, entry, _val_) do { \
#define dictSetVal(d, entry, _val_) do { \
if ((d)->type->valDup) \
entry->v.val = (d)->type->valDup((d)->privdata, _val_); \
else \
entry->v.val = (_val_); \
} while(0)

#define dictFreeEntryKey(d, entry) \
#define dictFreeKey(d, entry) \
if ((d)->type->keyDestructor) \
(d)->type->keyDestructor((d)->privdata, (entry)->key)

#define dictSetHashKey(d, entry, _key_) do { \
#define dictSetKey(d, entry, _key_) do { \
if ((d)->type->keyDup) \
entry->key = (d)->type->keyDup((d)->privdata, _key_); \
else \
entry->key = (_key_); \
} while(0)

#define dictCompareHashKeys(d, key1, key2) \
#define dictCompareKeys(d, key1, key2) \
(((d)->type->keyCompare) ? \
(d)->type->keyCompare((d)->privdata, key1, key2) : \
(key1) == (key2))

#define dictHashKey(d, key) (d)->type->hashFunction(key)

#define dictGetEntryKey(he) ((he)->key)
#define dictGetEntryVal(he) ((he)->v.val)
#define dictGetKey(he) ((he)->key)
#define dictGetVal(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)
Expand Down
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ robj *objectCommandLookup(redisClient *c, robj *key) {
dictEntry *de;

if ((de = dictFind(c->db->dict,key->ptr)) == NULL) return NULL;
return (robj*) dictGetEntryVal(de);
return (robj*) dictGetVal(de);
}

robj *objectCommandLookupOrReply(redisClient *c, robj *key, robj *reply) {
Expand Down
8 changes: 4 additions & 4 deletions src/pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int pubsubSubscribeChannel(redisClient *c, robj *channel) {
dictAdd(server.pubsub_channels,channel,clients);
incrRefCount(channel);
} else {
clients = dictGetEntryVal(de);
clients = dictGetVal(de);
}
listAddNodeTail(clients,c);
}
Expand Down Expand Up @@ -64,7 +64,7 @@ int pubsubUnsubscribeChannel(redisClient *c, robj *channel, int notify) {
/* Remove the client from the channel -> clients list hash table */
de = dictFind(server.pubsub_channels,channel);
redisAssertWithInfo(c,NULL,de != NULL);
clients = dictGetEntryVal(de);
clients = dictGetVal(de);
ln = listSearchKey(clients,c);
redisAssertWithInfo(c,NULL,ln != NULL);
listDelNode(clients,ln);
Expand Down Expand Up @@ -146,7 +146,7 @@ int pubsubUnsubscribeAllChannels(redisClient *c, int notify) {
int count = 0;

while((de = dictNext(di)) != NULL) {
robj *channel = dictGetEntryKey(de);
robj *channel = dictGetKey(de);

count += pubsubUnsubscribeChannel(c,channel,notify);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ int pubsubPublishMessage(robj *channel, robj *message) {
/* Send to clients listening for that channel */
de = dictFind(server.pubsub_channels,channel);
if (de) {
list *list = dictGetEntryVal(de);
list *list = dictGetVal(de);
listNode *ln;
listIter li;

Expand Down
Loading

0 comments on commit c0ba9eb

Please sign in to comment.