besched: Use sched_foreach_{after,reverse_before}().
[libfirm] / ir / adt / pset_new.h
index 6678608..fa37076 100644 (file)
@@ -1,15 +1,25 @@
+/*
+ * This file is part of libFirm.
+ * Copyright (C) 2012 University of Karlsruhe.
+ */
+
 /**
  * @file
  * @date    17.03.2007
- * @brief   A hashset that contains pointers
+ * @brief   hashset containing pointers
  * @author  Matthias Braun
- * @version $Id: pset_new.h 169 2007-04-03 01:01:09Z uxsm $
  *
- * NOTE: This has been named pset_new_new for now until all code has been changed
- *       to use this instead of the old deprecated pset_new functions!
+ * @note This has been named pset_new_new for now until all code has been
+ *       changed to use this instead of the old deprecated pset_new functions!
+ *       This version performs better than pset in terms of speed and memory
+ *       usage and allows multiple iterators over the set
  */
-#ifndef _FIRM_PSET_NEW_H_
-#define _FIRM_PSET_NEW_H_
+#ifndef FIRM_ADT_PSET_NEW_H
+#define FIRM_ADT_PSET_NEW_H
+
+#include <stdbool.h>
+
+/** @cond PRIVATE */
 
 #define HashSet          pset_new_t
 #define HashSetIterator  pset_new_iterator_t
 #undef HashSetIterator
 #undef ValueType
 
+/** @endcond */
+
+/** a pointer (hash)set */
+typedef struct pset_new_t           pset_new_t;
+/** iterator over a pointer set.
+ * @see #pset_new_t */
+typedef struct pset_new_iterator_t  pset_new_iterator_t;
+
 /**
  * Initializes a pset_new
  *
@@ -31,8 +49,8 @@ void pset_new_init(pset_new_t *pset_new);
 /**
  * Initializes a pset_new
  *
- * @param pset_new                Pointer to allocated space for the pset_new
- * @param expected_elements   Number of elements expected in the pset_new (rougly)
+ * @param pset_new            Pointer to allocated space for the pset_new
+ * @param expected_elements   Number of elements expected in the pset_new (roughly)
  */
 void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
 
@@ -49,9 +67,9 @@ void pset_new_destroy(pset_new_t *pset_new);
  *
  * @param pset_new   Pointer to the pset_new
  * @param ptr    Pointer to insert into the pset_new
- * @returns      1 if the pointer was inserted, 0 if it was already there
+ * @returns      true if the pointer was inserted, false if it was already there
  */
-int pset_new_insert(pset_new_t *pset_new, void *ptr);
+bool pset_new_insert(pset_new_t *pset_new, void *ptr);
 
 /**
  * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
@@ -67,9 +85,8 @@ void pset_new_remove(pset_new_t *pset_new, const void *ptr);
  *
  * @param pset_new   Pointer to the pset_new
  * @param ptr    The pointer to test
- * @returns      1 @p pset_new contains the @p ptr, 0 otherwise
  */
-int pset_new_contains(const pset_new_t *pset_new, const void *ptr);
+bool pset_new_contains(const pset_new_t *pset_new, const void *ptr);
 
 /**
  * Returns the number of pointers contained in the pset_new
@@ -107,4 +124,12 @@ void* pset_new_iterator_next(pset_new_iterator_t *iterator);
  */
 void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
 
+/**
+ * Convenience macro for iterating over a pset_new.
+ */
+#define foreach_pset_new(pset_new, type, ptr, iter)    \
+       for(pset_new_iterator_init(&iter, pset_new), \
+               ptr = (type) pset_new_iterator_next(&iter);     \
+               ptr != NULL; ptr = (type) pset_new_iterator_next(&iter))
+
 #endif