fix
[libfirm] / ir / adt / set.h
index a97ca62..8236152 100644 (file)
@@ -1,23 +1,30 @@
 /*
- * Project:     libFIRM
- * File name:   ir/adt/set.h
- * Purpose:     Declarations for set.
- * Author:      Markus Armbruster
- * Modified by:
- * Created:     1999 by getting from fiasco
- * CVS-ID:      $Id$
- * Copyright:   (c) 1995, 1996 Markus Armbruster
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 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.
  */
 
 /**
- * @file set.h
- *
- * Declarations for set.
+ * @file
+ * @brief       hashset: datastructure containing objects accessible by their key
+ * @author      Markus Armbruster
+ * @verison     $Id$
  */
-
-#ifndef _SET_H
-#define _SET_H
+#ifndef FIRM_ADT_SET_H
+#define FIRM_ADT_SET_H
 
 #include <stddef.h>
 
@@ -35,8 +42,8 @@ typedef struct set set;
 typedef struct set_entry {
   unsigned hash;    /**< the hash value of the element */
   size_t size;      /**< the size of the element */
-  int dptr[1];                 /**< the element itself, data copied in must not need more
-                                  alignment than this */
+  int dptr[1];     /**< the element itself, data copied in must not need more
+                         alignment than this */
 } set_entry;
 
 /**
@@ -50,17 +57,18 @@ typedef struct set_entry {
  *    0 if the elements are identically, non-zero else
  *
  * @note
- *    Although it is possible to define different meanings for equality of two
- *    elements of a sets, they can be only equal if there sizes are
- *    equal. This is checked before the compare function is called.
+ *    Although it is possible to define different meanings of equality
+ *    of two elements of a set, they can be only equal if their sizes are
+ *    are equal. This is checked before the compare function is called.
  */
 typedef int (*set_cmp_fun) (const void *elt, const void *key, size_t size);
 
 /**
  * Creates a new set.
  *
- * @param func    the compare function of this set
- * @param slots   number of initial slots
+ * @param func    The compare function of this set.
+ * @param slots   Initial number of collision chains.  I.e., #slots
+ *                different keys can be hashed without collisions.
  *
  * @returns
  *    created set
@@ -103,7 +111,7 @@ void *set_find (set *set, const void *key, size_t size, unsigned hash);
  * @return a pointer to the inserted element
  *
  * @note
- *    It is not possible to insert on element more than once. If an element
+ *    It is not possible to insert one element more than once. If an element
  *    that should be inserted is already in the set, this functions does
  *    nothing but returning its pointer.
  */
@@ -164,13 +172,21 @@ void *set_next (set *set);
 
 /**
  * Breaks the iteration of a set. Must be called before
- * the next pset_first() call if the iteration was NOT
+ * the next set_first() call if the iteration was NOT
  * finished.
  *
- * @param pset  the pset
+ * @param set  the set
  */
 void set_break (set *set);
 
+/**
+ * Iterates over an set.
+ *
+ * @param set    the set
+ * @param entry  the iterator
+ */
+#define foreach_set(set, entry) for (entry = set_first(set); entry; entry = set_next(set))
+
 /* implementation specific */
 #define new_set(cmp, slots) (SET_TRACE (new_set) ((cmp), (slots)))
 #define set_find(set, key, size, hash) \
@@ -196,7 +212,16 @@ void set_stats (set *set);
 #endif
 
 #ifdef DEBUG
-void set_describe (set *);
+/**
+ * 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
+ */
+void set_describe (set *set);
 #endif