X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fhash.h;h=61bc917a6cd45c35d7d4efc0db996db3d7005804;hb=3568d5658492aa0ad70ca3abfb683b53978c0d88;hp=8d0eff235c38348e4e7afbb5b9667aa33510e51d;hpb=1fd06503004016a245257a08748473d749559586;p=rocksndiamonds.git diff --git a/src/libgame/hash.h b/src/libgame/hash.h index 8d0eff23..61bc917a 100644 --- a/src/libgame/hash.h +++ b/src/libgame/hash.h @@ -121,6 +121,8 @@ struct hashtable_itr unsigned int index; }; +typedef struct hashtable HashTable; + /***************************************************************************** * create_hashtable_ext @@ -196,6 +198,24 @@ static int fnname (struct hashtable *h, keytype *k, valuetype *v) \ return hashtable_change(h, k, v); \ } +/***************************************************************************** + * hashtable_exists + + * @name hashtable_exists + * @param h the hashtable to search + * @param k the key to search for + * @return non-zero if key exists, else zero + */ + +int +hashtable_exists(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_EXISTS(fnname, keytype, valuetype) \ +static int fnname (struct hashtable *h, keytype *k) \ +{ \ + return hashtable_exists(h, k); \ +} + /***************************************************************************** * hashtable_search @@ -279,4 +299,64 @@ hashtable_iterator_value(struct hashtable_itr *i); int hashtable_iterator_advance(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* hashtable_fn - prototype of function to call for hashtable entry + + * @name hashtable_fn + * @param k the key of the current hash entry + * @param v the value of the current hash entry + * @param u additional user data + */ + +typedef void (*hashtable_fn) (void *k, void *v, void *u); + +/*****************************************************************************/ +/* hashtable_foreach - call function for all hashtable entries + + * @name hashtable_foreach + * @param h the hashtable to iterate through + * @param fn the function to call for each entry + */ + +void +hashtable_foreach(struct hashtable *h, hashtable_fn fn, void *userdata); + +/*****************************************************************************/ +/* hashtable_remove_fn - prototype of function to call for hashtable entry + + * @name hashtable_remove_fn + * @param k the key of the current hash entry + * @param v the value of the current hash entry + * @param u additional user data + * @return non-zero if entry should be removed, else zero + */ + +typedef int (*hashtable_remove_fn) (void *k, void *v, void *u); + +/*****************************************************************************/ +/* hashtable_foreach_remove - call function for all hashtable entries and remove them, + * if function returned 1 + * returns the number of removed entries + + * @name hashtable_foreach_remove + * @param h the hashtable to iterate through + * @param fn the function to call for each entry + * @return the number of removed entries + */ + +unsigned int +hashtable_foreach_remove(struct hashtable *h, hashtable_remove_fn fn, void *userdata); + +/*****************************************************************************/ +/* hashtable_remove_all - remove_all hashtable entries + + * @name hashtable_remove + * @param h the hashtable to remove all entries from + * @return the number of removed entries + */ + +unsigned int +hashtable_remove_all(struct hashtable *h); + #endif