fixed inline to INLINE
[libfirm] / ir / adt / cpset.h
1 /**
2  * @file
3  * @date    16.03.2007
4  * @brief   a set of pointers with a custom compare function
5  * @author  Matthias Braun
6  * @version $Id$
7  */
8 #ifndef _FIRM_CPSET_H_
9 #define _FIRM_CPSET_H_
10
11 /**
12  * The type of a cpset compare function.
13  *
14  * @param p1   pointer to an element
15  * @param p2   pointer to another element
16  *
17  * @return  1 if the elements are identically, zero else
18  */
19 typedef int (*cpset_cmp_function) (const void *p1, const void *p2);
20
21 /**
22  * The type of a cpset hash function.
23  *
24  * @param p1   pointer to an element
25  * @param p2   pointer to another element
26  *
27  * @return  1 if the elements are identically, zero else
28  */
29 typedef unsigned (*cpset_hash_function) (const void *obj);
30
31 #define HashSet          cpset_t
32 #define HashSetIterator  cpset_iterator_t
33 #define HashSetEntry     cpset_hashset_entry_t
34 #define ValueType        void*
35 #define ADDITIONAL_DATA  cpset_cmp_function cmp_function; cpset_hash_function hash_function;
36 #include "hashset.h"
37 #undef ADDITIONAL_DATA
38 #undef ValueType
39 #undef HashSetEntry
40 #undef HashSetIterator
41 #undef HashSet
42
43 /**
44  * Initializes a cpset
45  *
46  * @param cpset        Pointer to allocated space for the cpset
47  * @param cmp_function The compare function to use
48  */
49 void cpset_init(cpset_t *cpset, cpset_hash_function hash_function,
50                 cpset_cmp_function cmp_function);
51
52 /**
53  * Initializes a cpset
54  *
55  * @param cpset               Pointer to allocated space for the cpset
56  * @param cmp_function        The compare function to use
57  * @param expected_elements   Number of elements expected in the cpset (rougly)
58  */
59 void cpset_init_size(cpset_t *cpset, cpset_hash_function hash_function,
60                      cpset_cmp_function cmp_function,
61                      size_t expected_elements);
62
63 /**
64  * Destroys a cpset and frees the memory allocated for hashtable. The memory of
65  * the cpset itself is not freed.
66  *
67  * @param cpset   Pointer to the cpset
68  */
69 void cpset_destroy(cpset_t *cpset);
70
71 /**
72  * Inserts an element into a cpset.
73  *
74  * @param cpset   Pointer to the cpset
75  * @param obj     Element to insert into the cpset
76  * @returns       The element itself or a pointer to an existing element
77  */
78 void* cpset_insert(cpset_t *cpset, void *obj);
79
80 /**
81  * Removes an element from a cpset. Does nothing if the cpset doesn't contain the
82  * element.
83  *
84  * @param cpset   Pointer to the cpset
85  * @param obj     Pointer to remove from the cpset
86  */
87 void cpset_remove(cpset_t *cpset, const void *obj);
88
89 /**
90  * Tests whether a cpset contains a pointer
91  *
92  * @param cpset   Pointer to the cpset
93  * @param obj     The pointer to find
94  * @returns       An equivalent object to @p obj or NULL
95  */
96 void *cpset_find(const cpset_t *cpset, const void *obj);
97
98 /**
99  * Returns the number of pointers contained in the cpset
100  *
101  * @param cpset   Pointer to the cpset
102  * @returns       Number of pointers contained in the cpset
103  */
104 size_t cpset_size(const cpset_t *cpset);
105
106 /**
107  * Initializes a cpset iterator. Sets the iterator before the first element in
108  * the cpset.
109  *
110  * @param iterator   Pointer to already allocated iterator memory
111  * @param cpset       Pointer to the cpset
112  */
113 void cpset_iterator_init(cpset_iterator_t *iterator, const cpset_t *cpset);
114
115 /**
116  * Advances the iterator and returns the current element or NULL if all elements
117  * in the cpset have been processed.
118  * @attention It is not allowed to use cpset_insert or cpset_remove while
119  *            iterating over a cpset.
120  *
121  * @param iterator  Pointer to the cpset iterator.
122  * @returns         Next element in the cpset or NULL
123  */
124 void *cpset_iterator_next(cpset_iterator_t *iterator);
125
126 /**
127  * Removed the element the iterator currently points to
128  *
129  * @param cpset     Pointer to the cpset
130  * @param iterator  Pointer to the cpset iterator.
131  */
132 void cpset_remove_iterator(cpset_t *cpset, const cpset_iterator_t *iterator);
133
134 #endif