/*
- * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
- *
* This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @brief optimized version of set for sets containing only pointers
* (deprecated)
* @author Markus Armbruster
- * @note This code has been deprecated. Use pset_new or cpset for new
- * code.
*/
#ifndef FIRM_ADT_PSET_H
#define FIRM_ADT_PSET_H
#include <stddef.h>
#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.
* @param x A pointer.
*/
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 its meta-information */
typedef struct {
- unsigned hash;
- void *dptr;
+ unsigned hash; /**< hash value of element */
+ void *dptr; /**< pointer to element data */
} pset_entry;
/**
*/
FIRM_API void *pset_first(pset *pset);
+/**
+ * Returns the first element of a pset.
+ * This is a wrapper for pset_first(set); 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
+ */
+#define pset_first(type, pset) ((type*)pset_first((pset)))
+
/**
* Returns the next element of a pset.
*
*/
FIRM_API void *pset_next(pset *pset);
+/**
+ * Returns the next element of a pset.
+ * This is a wrapper for pset_next(set); 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
* the next pset_first() call if the iteration was NOT
* @param type type of iterator variable
* @param entry the iterator
*/
-#define foreach_pset(pset, type, entry) for (entry = (type)pset_first(pset); entry; entry = (type)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
*/
FIRM_API void pset_insert_pset_ptr(pset *target, pset *src);
+/** @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_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
-
-/* Private */
-
typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
FIRM_API void *_pset_search(pset *, const void *, unsigned, _pset_action);
+/** @endcond */
+
+/** @} */
+
#include "../end.h"
#endif