forgot to add new files
[libfirm] / ir / ir / iredgeset.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @author    Matthias Braun
23  * @date      12.01.2008
24  * @brief     An edgeset.
25  * @version   $Id$
26  */
27 #ifndef _FIRM_IREDGESET_H_
28 #define _FIRM_IREDGESET_H_
29
30 #include "firm_config.h"
31
32 #include "firm_types.h"
33 #include "xmalloc.h"
34
35 #define HashSet          ir_edgeset_t
36 #define HashSetIterator  ir_edgeset_iterator_t
37 #define ValueType        ir_edge_t*
38 #define DO_REHASH
39
40 #include "hashset.h"
41
42 #undef DO_REHASH
43 #undef ValueType
44 #undef HashSetIterator
45 #undef HashSet
46
47 typedef struct ir_edgeset_t          ir_edgeset_t;
48 typedef struct ir_edgeset_iterator_t ir_edgeset_iterator_t;
49
50 /**
51  * Initializes a edgeset with default size.
52  *
53  * @param edgeset      Pointer to allocated space for the edgeset
54  */
55 void ir_edgeset_init(ir_edgeset_t *edgeset);
56
57 /**
58  * Destroys a edgeset and frees the memory allocated for hashtable. The memory of
59  * the edgeset itself is not freed.
60  *
61  * @param edgeset   Pointer to the edgeset
62  */
63 void ir_edgeset_destroy(ir_edgeset_t *edgeset);
64
65 /**
66  * Inserts a edge into a edgeset.
67  *
68  * @param edgeset   Pointer to the edgeset
69  * @param edge      edge to insert into the edgeset
70  */
71 ir_edge_t *ir_edgeset_insert(ir_edgeset_t *edgeset, ir_edge_t *edge);
72
73
74 /**
75  * Removes a edge from a edgeset. Does nothing if the edgeset doesn't contain
76  * the edge.
77  *
78  * @param edgeset  Pointer to the edgeset
79  * @param edge     Node to remove from the edgeset
80  */
81 void ir_edgeset_remove(ir_edgeset_t *edgeset, const ir_edge_t *edge);
82
83 /**
84  * Tests whether a edgeset contains a specific edge
85  *
86  * @param edgeset   Pointer to the edgeset
87  * @param edge      The pointer to find
88  * @returns         1 if edgeset contains the edge, 0 else
89  */
90 int ir_edgeset_contains(const ir_edgeset_t *edgeset, const ir_edge_t *edge);
91
92 /**
93  * Initializes a edgeset iterator. Sets the iterator before the first element in
94  * the edgeset.
95  *
96  * @param iterator   Pointer to already allocated iterator memory
97  * @param edgeset       Pointer to the edgeset
98  */
99 void ir_edgeset_iterator_init(ir_edgeset_iterator_t *iterator,
100                               const ir_edgeset_t *edgeset);
101
102 /**
103  * Advances the iterator and returns the current element or NULL if all elements
104  * in the edgeset have been processed.
105  * @attention It is not allowed to use edgeset_insert or edgeset_remove while
106  *            iterating over a edgeset.
107  *
108  * @param iterator  Pointer to the edgeset iterator.
109  * @returns         Next element in the edgeset or NULL
110  */
111 ir_edge_t *ir_edgeset_iterator_next(ir_edgeset_iterator_t *iterator);
112
113 /**
114  * Removes the element the iterator currently points to
115  *
116  * @param edgeset   Pointer to the edgeset
117  * @param iterator  Pointer to the edgeset iterator.
118  */
119 void ir_edgeset_remove_iterator(ir_edgeset_t *edgeset,
120                                 const ir_edgeset_iterator_t *iterator);
121
122 #define foreach_ir_edgeset(edgeset, edge, iter) \
123         for(ir_edgeset_iterator_init(&iter, edgeset), \
124         edge = ir_edgeset_iterator_next(&iter);    \
125                 edge != NULL; edge = ir_edgeset_iterator_next(&iter))
126
127 #endif