X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=include%2Flibfirm%2Fadt%2Fset.h;h=f2235bdb261473d1db3e29f3e7db2e65fbd6b303;hb=43b545e3269a432382c13559abc75c15ebde83e7;hp=fccae07f8a02440ac4ad91cdb334a51d9184d261;hpb=5c6f5d46bf3f00d048c8e5357902fbe5b39a8d73;p=libfirm diff --git a/include/libfirm/adt/set.h b/include/libfirm/adt/set.h index fccae07f8..f2235bdb2 100644 --- a/include/libfirm/adt/set.h +++ b/include/libfirm/adt/set.h @@ -21,7 +21,6 @@ * @file * @brief hashset: datastructure containing objects accessible by their key * @author Markus Armbruster - * @version $Id$ */ #ifndef FIRM_ADT_SET_H #define FIRM_ADT_SET_H @@ -30,6 +29,14 @@ #include "../begin.h" +/** + * @ingroup adt + * @defgroup set Generic Hashset + * Generic Hashset + * @note This code has been deprecated. Use hashset for new code. + * @{ + */ + /** * The abstract type of a set. * @@ -164,6 +171,18 @@ FIRM_API set_entry *set_hinsert0(set *set, const void *key, size_t size, unsigne */ FIRM_API void *set_first(set *set); +/** + * Returns the first element of a set. + * This is a wrapper for set_first(set *set); It allows to express the + * intended type of the set elements (instead of weakly typed void*). + * + * @param set the set to iterate + * @param type type of the set elements + * + * @return a pointer to the element or NULL if the set is empty + */ +#define set_first(type, set) ((type*)set_first((set))) + /** * Returns the next element of a set. * @@ -174,6 +193,19 @@ FIRM_API void *set_first(set *set); */ FIRM_API void *set_next(set *set); +/** + * Returns the next element of a set. + * This is a wrapper for set_next(set *set); It allows to express the + * intended type of the set elements (instead of weakly typed void*). + * + * @param set the set to iterate + * @param type type of the set elements + * + * @return a pointer to the next element or NULL if the + * iteration is finished + */ +#define set_next(type, set) ((type*)set_next((set))) + /** * Breaks the iteration of a set. Must be called before * the next set_first() call if the iteration was NOT @@ -190,52 +222,29 @@ FIRM_API void set_break(set *set); * @param type type of iterator variable * @param entry the iterator */ -#define foreach_set(set, type, entry) for (entry = (type) set_first(set); entry; entry = (type) set_next(set)) +#define foreach_set(set, type, entry) for (type *entry = set_first(type, set); entry; entry = set_next(type, set)) + +/** @cond PRIVATE */ /* implementation specific */ #define new_set(cmp, slots) ((new_set) ((cmp), (slots))) -#define set_find(set, key, size, hash) \ - _set_search ((set), (key), (size), (hash), _set_find) -#define set_insert(set, key, size, hash) \ - _set_search ((set), (key), (size), (hash), _set_insert) +#define set_find(type, set, key, size, hash) \ + ((type*)_set_search((set), 1 ? (key) : (type*)0 /* type check */, (size), (hash), _set_find)) +#define set_insert(type, set, key, size, hash) \ + ((type*)_set_search((set), 1 ? (key) : (type*)0 /* type check */, (size), (hash), _set_insert)) #define set_hinsert(set, key, size, hash) \ ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert)) #define set_hinsert0(set, key, size, hash) \ ((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert0)) -#define SET_VRFY(set) (void)0 - -#ifdef STATS -/** - * Prints statistics on a set to stdout. - * - * @param set the set - */ -void set_stats (set *set); -#else -# define set_stats(s) ((void)0) -#endif - -#ifdef DEBUG -/** - * Describe a set. - * - * Writes a description of a set to stdout. The description includes: - * - a header telling how many elements (nkey) and segments (nseg) are in use - * - for every collision chain the number of element with its hash values - * - * @param set the set - */ -FIRM_API void set_describe(set *set); -#endif - - -/* Private */ - typedef enum { _set_find, _set_insert, _set_hinsert, _set_hinsert0 } _set_action; FIRM_API void *_set_search(set *, const void *, size_t, unsigned, _set_action); +/** @endcond */ + +/** @} */ + #include "../end.h" #endif