X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=include%2Flibfirm%2Fadt%2Fpset.h;h=11d740ca1393cf039deb9930166812942c7b09f0;hb=8b9cffd15955b08311c41c37cd06acd7db3bd7f4;hp=058cbabec49d0a54da92e9c39d916f85265a363f;hpb=acbdf295cc01d5b69b1cb8ea2c7764dca1e7b8ac;p=libfirm diff --git a/include/libfirm/adt/pset.h b/include/libfirm/adt/pset.h index 058cbabec..11d740ca1 100644 --- a/include/libfirm/adt/pset.h +++ b/include/libfirm/adt/pset.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -22,9 +22,6 @@ * @brief optimized version of set for sets containing only pointers * (deprecated) * @author Markus Armbruster - * @version $Id$ - * @note This code has been deprecated. Use pset_new or cpset for new - * code. */ #ifndef FIRM_ADT_PSET_H #define FIRM_ADT_PSET_H @@ -32,7 +29,16 @@ #include #include "hashptr.h" -#include "iterator.h" + +#include "../begin.h" + +/** + * @ingroup adt + * @defgroup pset Pointer Set + * (Hash)sets containing pointers. + * @note This code has been deprecated. Use pset_new or cpset for new code. + * @{ + */ /** * The default comparison function for pointers. @@ -40,7 +46,7 @@ * @param y A pointer. * @return 0 if @p x and @p y are equal. Some value != 0 otherwise. */ -int pset_default_ptr_cmp(const void *x, const void *y); +FIRM_API int pset_default_ptr_cmp(const void *x, const void *y); /** * The abstract type of a pset (Set of pointers). @@ -52,20 +58,23 @@ int pset_default_ptr_cmp(const void *x, const void *y); */ typedef struct pset pset; -/* - * Define some convenience macros using the predefined hash function. - */ -#define pset_insert_ptr(set,key) pset_insert(set, key, HASH_PTR(key)) -#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, HASH_PTR(key)) -#define pset_remove_ptr(set,key) pset_remove(set, key, HASH_PTR(key)) -#define pset_find_ptr(set,key) pset_find(set, key, HASH_PTR(key)) +/** Inserts into pointer set with default hash function. */ +#define pset_insert_ptr(set,key) pset_insert(set, key, hash_ptr(key)) +/** Inserts into pointer set with default hash function and return entry */ +#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, hash_ptr(key)) +/** Removes pointer from pointer set with default hash function */ +#define pset_remove_ptr(set,key) pset_remove(set, key, hash_ptr(key)) +/** Finds pointer in pointer set with default hash function */ +#define pset_find_ptr(set,key) pset_find(set, key, hash_ptr(key)) +/** Creates new pointer set with default compare function */ #define pset_new_ptr(slots) new_pset(pset_default_ptr_cmp, slots) +/** Creates new pointer set with default compare function and default size */ #define pset_new_ptr_default() pset_new_ptr(64) -/** The entry of a pset, representing an element pointer in the set and it's meta-information */ +/** The entry of a pset, representing an element pointer in the set and its meta-information */ typedef struct { - unsigned hash; - void *dptr; + unsigned hash; /**< hash value of element */ + void *dptr; /**< pointer to element data */ } pset_entry; /** @@ -89,7 +98,7 @@ typedef int (*pset_cmp_fun) (const void *elt, const void *key); * @returns * created pset */ -pset *new_pset (pset_cmp_fun func, int slots); +FIRM_API pset *new_pset(pset_cmp_fun func, size_t slots); /** * Deletes a pset. @@ -97,16 +106,16 @@ pset *new_pset (pset_cmp_fun func, int slots); * @param pset the pset * * @note - * This does NOT delete the elements of this pset, just it's pointers! + * This does NOT delete the elements of this pset, just its pointers! */ -void del_pset (pset *pset); +FIRM_API void del_pset(pset *pset); /** * Returns the number of elements in a pset. * * @param pset the pset */ -int pset_count (pset *pset); +FIRM_API size_t pset_count(pset *pset); /** * Searches an element pointer in a pset. @@ -118,7 +127,7 @@ int pset_count (pset *pset); * @return * the pointer of the found element in the pset or NULL if it was not found */ -void *pset_find (pset *pset, const void *key, unsigned hash); +FIRM_API void *pset_find(pset *pset, const void *key, unsigned hash); /** * Inserts an element pointer into a pset. @@ -135,7 +144,7 @@ void *pset_find (pset *pset, const void *key, unsigned hash); * nothing but returning its already existing set_entry. */ -void *pset_insert (pset *pset, const void *key, unsigned hash); +FIRM_API void *pset_insert(pset *pset, const void *key, unsigned hash); /** * Inserts an element pointer into a pset and returns its pset_entry. @@ -151,7 +160,7 @@ void *pset_insert (pset *pset, const void *key, unsigned hash); * that should be inserted is already in the pset, this functions does * nothing but returning its pset_entry. */ -pset_entry *pset_hinsert (pset *pset, const void *key, unsigned hash); +FIRM_API pset_entry *pset_hinsert(pset *pset, const void *key, unsigned hash); /** * Removes an element from a pset. @@ -169,16 +178,28 @@ pset_entry *pset_hinsert (pset *pset, const void *key, unsigned hash); * Further, it is allowed to remove elements during an iteration * including the current one. */ -void *pset_remove (pset *pset, const void *key, unsigned hash); +FIRM_API void *pset_remove(pset *pset, const void *key, unsigned hash); + +/** + * Returns the first element of a pset. + * + * @param pset the pset to iterate + * + * @return a pointer to the element or NULL if the set is empty + */ +FIRM_API void *pset_first(pset *pset); /** * Returns the first element of a pset. + * This is a wrapper for pset_first(pmap *map); It allows to express the + * intended type of the set elements (instead of weakly typed void*). * + * @param type destination type of the pointers in the set * @param pset the pset to iterate * * @return a pointer to the element or NULL if the set is empty */ -void *pset_first (pset *pset); +#define pset_first(type, pset) ((type*)pset_first((pset))) /** * Returns the next element of a pset. @@ -188,7 +209,20 @@ void *pset_first (pset *pset); * @return a pointer to the next element or NULL if the * iteration is finished */ -void *pset_next (pset *pset); +FIRM_API void *pset_next(pset *pset); + +/** + * Returns the next element of a pset. + * This is a wrapper for pset_next(pmap *map); It allows to express the + * intended type of the set elements (instead of weakly typed void*). + * + * @param type destination type of the pointers in the set + * @param pset the pset to iterate + * + * @return a pointer to the next element or NULL if the + * iteration is finished + */ +#define pset_next(type, pset) ((type*)pset_next((pset))) /** * Breaks the iteration of a set. Must be called before @@ -197,15 +231,16 @@ void *pset_next (pset *pset); * * @param pset the pset */ -void pset_break (pset *pset); +FIRM_API void pset_break(pset *pset); /** * Iterates oven an pset. * * @param pset the pset + * @param type type of iterator variable * @param entry the iterator */ -#define foreach_pset(pset, entry) for (entry = pset_first(pset); entry; entry = pset_next(pset)) +#define foreach_pset(pset, type, entry) for (type *entry = pset_first(type, pset); entry; entry = pset_next(type, pset)) /** * Inserts all elements of the pointer set src into @@ -214,9 +249,11 @@ void pset_break (pset *pset); * @param target the target set, will contain the union * @param src a set, will not be changed */ -void pset_insert_pset_ptr(pset *target, pset *src); +FIRM_API void pset_insert_pset_ptr(pset *target, pset *src); -#define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots))) +/** @cond PRIVATE */ + +#define new_pset(cmp, slots) ((new_pset) ((cmp), (slots))) #define pset_find(pset, key, hash) \ _pset_search ((pset), (key), (hash), _pset_find) #define pset_insert(pset, key, hash) \ @@ -224,49 +261,14 @@ void pset_insert_pset_ptr(pset *target, pset *src); #define pset_hinsert(pset, key, hash) \ ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert)) -#ifdef STATS -/** - * Prints statistics on a set to stdout. - * - * @param pset the pset - */ -void pset_stats (pset *pset); -#else -# define pset_stats(s) ((void)0) -#endif - -#ifdef DEBUG -/** - * Describe a pset. - * - * 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 pset the pset - */ -void pset_describe (pset *pset); -#endif - -/* @@@ NYI */ -#define PSET_VRFY(pset) (void)0 +typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action; +FIRM_API void *_pset_search(pset *, const void *, unsigned, _pset_action); -/* Private */ +/** @endcond */ -typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action; +/** @} */ -void *_pset_search (pset *, const void *, unsigned, _pset_action); - -#if defined(DEBUG) && defined(HAVE_GNU_MALLOC) -extern const char *pset_tag; -# ifdef PSET_ID -# define PSET_TRACE pset_tag = SET_ID, -# else -# define PSET_TRACE pset_tag = __FILE__, -# endif -#else /* !(DEBUG && HAVE_GNU_MALLOC) */ -# define PSET_TRACE -#endif /* !(DEBUG && HAVE_GNU_MALLOC) */ +#include "../end.h" #endif