added dictFetchValue() to dict.c to make hash table API a bit less verbose in the common cases

This commit is contained in:
antirez 2010-04-16 10:04:51 +02:00
parent d4dd6556c3
commit 58e1c9c143
2 changed files with 8 additions and 0 deletions

7
dict.c
View File

@ -423,6 +423,13 @@ dictEntry *dictFind(dict *d, const void *key)
return NULL;
}
void *dictFetchValue(dict *d, const void *key) {
dictEntry *he;
he = dictFind(d,key);
return he ? dictGetEntryVal(he) : NULL;
}
dictIterator *dictGetIterator(dict *d)
{
dictIterator *iter = _dictAlloc(sizeof(*iter));

1
dict.h
View File

@ -129,6 +129,7 @@ int dictDelete(dict *d, const void *key);
int dictDeleteNoFree(dict *d, const void *key);
void dictRelease(dict *d);
dictEntry * dictFind(dict *d, const void *key);
void *dictFetchValue(dict *d, const void *key);
int dictResize(dict *d);
dictIterator *dictGetIterator(dict *d);
dictEntry *dictNext(dictIterator *iter);