Removed arning
[libfirm] / ir / adt / set.h
index 8d32bab..f0991d7 100644 (file)
@@ -1,7 +1,14 @@
-/* Declarations for set.
-   Copyright (C) 1995, 1996 Markus Armbruster */
-
-/* $Id$ */
+/*
+ * 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.
+ */
 
 /**
  * @file set.h
 
 #include <stddef.h>
 
-/** The type of a set. */
+/**
+ * The abstract type of a set.
+ *
+ * This sets stores copies of its elements, so there is no need
+ * to store the elements after they were added to a set.
+ *
+ * @see pset
+ */
 typedef struct set set;
 
-/** an entry of a set */
+/** The entry of a set, representing an element in the set and it's meta-information */
 typedef struct set_entry {
-  unsigned hash;
-  size_t size;
-  int dptr[1];                 /**< data copied in must not need more
-                                  alignment than this */
+  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 */
 } set_entry;
 
-/** the type of a set compare function */
+/**
+ * The type of a set compare function.
+ *
+ * @param elt   pointer to an element
+ * @param key   pointer to another element
+ * @param size  size of the elements
+ *
+ * @return
+ *    0 if the elements are identically, non-zero else
+ *
+ * @note
+ *    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 */
-set *new_set (set_cmp_fun, int slots);
+/**
+ * Creates a new set.
+ *
+ * @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
+ */
+set *new_set (set_cmp_fun func, int slots);
 
-/** deletes a set */
-void del_set (set *);
+/**
+ * Deletes a set and all elements of it.
+ */
+void del_set (set *set);
 
-void *set_find (set *, const void *key, size_t, unsigned hash);
-void *set_insert (set *, const void *key, size_t, unsigned hash);
-set_entry *set_hinsert (set *, const void *key, size_t, unsigned hash);
+/**
+ * Returns the number of elements in a set.
+ *
+ * @param set   the set
+ */
+int set_count (set *set);
 
-/** returns the first element of a set */
-void *set_first (set *);
+/**
+ * Searches an element in a set.
+ *
+ * @param set   the set to search in
+ * @param key   the element to is searched
+ * @param size  the size of key
+ * @param hash  the hash value of key
+ *
+ * @return
+ *    The address of the found element in the set or NULL if it was not found.
+ */
+void *set_find (set *set, const void *key, size_t size, unsigned hash);
 
-/** returns the next element of a set */
-void *set_next (set *);
+/**
+ * Inserts an element into a set.
+ *
+ * @param set   the set to insert in
+ * @param key   a pointer to the element to be inserted.  Element is copied!
+ * @param size  the size of the element that should be inserted
+ * @param hash  the hash-value of the element
+ *
+ * @return a pointer to the inserted element
+ *
+ * @note
+ *    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.
+ */
+void *set_insert (set *set, const void *key, size_t size, unsigned hash);
 
-/** breaks the iteration of a set. Must be called before the next set_first() call */
-void set_break (set *);
+/**
+ * Inserts an element into a set and returns its set_entry.
+ *
+ * @param set   the set to insert in
+ * @param key   a pointer to the element to be inserted. Element is copied!
+ * @param size  the size of the element that should be inserted
+ * @param hash  the hash-value of the element
+ *
+ * @return a pointer to the set_entry of the inserted element
+ *
+ * @note
+ *    It is not possible to insert an element more than once. If an element
+ *    that should be inserted is already in the set, this functions does
+ *    nothing but returning its set_entry.
+ */
+set_entry *set_hinsert (set *set, const void *key, size_t size, unsigned hash);
+
+/**
+ * Inserts an element into a set, zero-terminate it and returns its set_entry.
+ *
+ * @param set   the set to insert in
+ * @param key   a pointer to the element to be inserted.  Element is copied!
+ * @param size  the size of the element that should be inserted
+ * @param hash  the hash-value of the element
+ *
+ * @return a pointer to the set_entry of the inserted element
+ *
+ * @note
+ *    It is not possible to insert on element more than once. If an element
+ *    that should be inserted is already in the set, this functions does
+ *    nothing but returning its set_entry.
+ */
+set_entry *set_hinsert0 (set *set, const void *key, size_t size, unsigned hash);
+
+/**
+ * Returns the first element of a set.
+ *
+ * @param set  the set to iterate
+ *
+ * @return a pointer to the element or NULL if the set is empty
+ */
+void *set_first (set *set);
+
+/**
+ * Returns the next element of a set.
+ *
+ * @param set  the set to iterate
+ *
+ * @return a pointer to the next element or NULL if the
+ *         iteration is finished
+ */
+void *set_next (set *set);
+
+/**
+ * Breaks the iteration of a set. Must be called before
+ * the next set_first() call if the iteration was NOT
+ * finished.
+ *
+ * @param set  the set
+ */
+void set_break (set *set);
 
+/* implementation specific */
 #define new_set(cmp, slots) (SET_TRACE (new_set) ((cmp), (slots)))
 #define set_find(set, key, size, hash) \
   _set_search ((set), (key), (size), (hash), _set_find)
@@ -54,23 +180,39 @@ void set_break (set *);
   _set_search ((set), (key), (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
-void set_stats (set *);
+/**
+ * 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
-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
 
 
 /* Private */
 
-typedef enum { _set_find, _set_insert, _set_hinsert } _set_action;
+typedef enum { _set_find, _set_insert, _set_hinsert, _set_hinsert0 } _set_action;
 
 void *_set_search (set *, const void *, size_t, unsigned, _set_action);