2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @author Matthias Braun
27 #ifndef _FIRM_IREDGESET_H_
28 #define _FIRM_IREDGESET_H_
30 #include "firm_config.h"
32 #include "firm_types.h"
34 #define HashSet ir_edgeset_t
35 #define HashSetIterator ir_edgeset_iterator_t
36 #define ValueType ir_edge_t*
43 #undef HashSetIterator
46 typedef struct ir_edgeset_t ir_edgeset_t;
47 typedef struct ir_edgeset_iterator_t ir_edgeset_iterator_t;
50 * Initializes a edgeset with default size.
52 * @param edgeset Pointer to allocated space for the edgeset
54 void ir_edgeset_init(ir_edgeset_t *edgeset);
57 * Destroys a edgeset and frees the memory allocated for hashtable. The memory of
58 * the edgeset itself is not freed.
60 * @param edgeset Pointer to the edgeset
62 void ir_edgeset_destroy(ir_edgeset_t *edgeset);
65 * Inserts a edge into a edgeset.
67 * @param edgeset Pointer to the edgeset
68 * @param edge edge to insert into the edgeset
70 ir_edge_t *ir_edgeset_insert(ir_edgeset_t *edgeset, ir_edge_t *edge);
74 * Removes a edge from a edgeset. Does nothing if the edgeset doesn't contain
77 * @param edgeset Pointer to the edgeset
78 * @param edge Node to remove from the edgeset
80 void ir_edgeset_remove(ir_edgeset_t *edgeset, const ir_edge_t *edge);
83 * Tests whether a edgeset contains a specific edge
85 * @param edgeset Pointer to the edgeset
86 * @param edge The pointer to find
87 * @returns 1 if edgeset contains the edge, 0 else
89 int ir_edgeset_contains(const ir_edgeset_t *edgeset, const ir_edge_t *edge);
92 * Initializes a edgeset iterator. Sets the iterator before the first element in
95 * @param iterator Pointer to already allocated iterator memory
96 * @param edgeset Pointer to the edgeset
98 void ir_edgeset_iterator_init(ir_edgeset_iterator_t *iterator,
99 const ir_edgeset_t *edgeset);
102 * Advances the iterator and returns the current element or NULL if all elements
103 * in the edgeset have been processed.
104 * @attention It is not allowed to use edgeset_insert or edgeset_remove while
105 * iterating over a edgeset.
107 * @param iterator Pointer to the edgeset iterator.
108 * @returns Next element in the edgeset or NULL
110 ir_edge_t *ir_edgeset_iterator_next(ir_edgeset_iterator_t *iterator);
113 * Removes the element the iterator currently points to
115 * @param edgeset Pointer to the edgeset
116 * @param iterator Pointer to the edgeset iterator.
118 void ir_edgeset_remove_iterator(ir_edgeset_t *edgeset,
119 const ir_edgeset_iterator_t *iterator);
121 #define foreach_ir_edgeset(edgeset, edge, iter) \
122 for(ir_edgeset_iterator_init(&iter, edgeset), \
123 edge = ir_edgeset_iterator_next(&iter); \
124 edge != NULL; edge = ir_edgeset_iterator_next(&iter))