X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fhash.c;h=89c7134f5906aa06d8a6cb24813eebf84f2d42af;hb=afba55b62615e9b162159c0f7b0df602f27f69a7;hp=101ec1214a30aae2faddd478c24f53321d401832;hpb=1fd06503004016a245257a08748473d749559586;p=rocksndiamonds.git diff --git a/src/libgame/hash.c b/src/libgame/hash.c index 101ec121..89c7134f 100644 --- a/src/libgame/hash.c +++ b/src/libgame/hash.c @@ -268,6 +268,29 @@ hashtable_change(struct hashtable *h, void *k, void *v) return 0; } +/*****************************************************************************/ +int /* checks if key exists */ +hashtable_exists(struct hashtable *h, void *k) +{ + struct entry *e; + unsigned int hashvalue, index; + + hashvalue = hash(h, k); + index = indexFor(h->tablelength, hashvalue); + e = h->table[index]; + + while (e != NULL) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + return 1; + + e = e->next; + } + + return 0; +} + /*****************************************************************************/ void * /* returns value associated with key */ hashtable_search(struct hashtable *h, void *k)