b82827242a85ade9b483a2db768a5de08c79ea49
[libfirm] / ir / ir / irnodemap.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      30.03.2007
24  * @brief     A nodemap. This should be prefered over a simple pset, because it
25  *            tries to guarantee deterministic behavior. (and is faster)
26  * @version   $Id$
27  * @note      Actually the bits to make the behaviour deterministic are not
28  *            implemented yet...
29  */
30 #ifndef _FIRM_IRNODEMAP_H_
31 #define _FIRM_IRNODEMAP_H_
32
33 #include "irnode.h"
34 #include "xmalloc.h"
35
36 typedef struct ir_nodemap_entry_t {
37         const ir_node *node;
38         void          *data;
39 } ir_nodemap_entry_t;
40
41 #define HashSet          ir_nodemap_t
42 #define HashSetIterator  ir_nodemap_iterator_t
43 #define ValueType        ir_nodemap_entry_t
44 #define DO_REHASH
45 #include "hashset.h"
46 #undef DO_REHASH
47 #undef ValueType
48 #undef HashSetIterator
49 #undef HashSet
50
51 typedef struct ir_nodemap_t           ir_nodemap_t;
52 typedef struct ir_nodemap_iterator_t  ir_nodemap_iterator_t;
53
54 /**
55  * Initializes a nodemap with default size.
56  *
57  * @param nodemap      Pointer to allocated space for the nodemap
58  */
59 void ir_nodemap_init(ir_nodemap_t *nodemap);
60
61 /**
62  * Initializes a nodemap
63  *
64  * @param nodemap             Pointer to allocated space for the nodemap
65  * @param expected_elements   Number of elements expected in the nodemap (roughly)
66  */
67 void ir_nodemap_init_size(ir_nodemap_t *nodemap, size_t expected_elements);
68
69 /**
70  * Destroys a nodemap and frees the memory allocated for hashtable. The memory of
71  * the nodemap itself is not freed.
72  *
73  * @param nodemap   Pointer to the nodemap
74  */
75 void ir_nodemap_destroy(ir_nodemap_t *nodemap);
76
77 /**
78  * Inserts a node into a nodemap.
79  *
80  * @param nodemap   Pointer to the nodemap
81  * @param node      node to insert into the nodemap
82  * @param data      data to associate with the node
83  */
84 void ir_nodemap_insert(ir_nodemap_t *nodemap, const ir_node *node, void *data);
85
86 /**
87  * Removes a node from a nodemap. Does nothing if the nodemap doesn't contain
88  * the node.
89  *
90  * @param nodemap  Pointer to the nodemap
91  * @param node     Node to remove from the nodemap
92  */
93 void ir_nodemap_remove(ir_nodemap_t *nodemap, const ir_node *node);
94
95 /**
96  * Tests whether a nodemap contains a specific node
97  *
98  * @param nodemap   Pointer to the nodemap
99  * @param node      The pointer to find
100  * @returns         1 if nodemap contains the node, 0 else
101  */
102 void *ir_nodemap_get(const ir_nodemap_t *nodemap, const ir_node *node);
103
104 /**
105  * Returns the number of pointers contained in the nodemap
106  *
107  * @param nodemap   Pointer to the nodemap
108  * @returns       Number of pointers contained in the nodemap
109  */
110 size_t ir_nodemap_size(const ir_nodemap_t *nodemap);
111
112 #if 0
113 /**
114  * Initializes a nodemap iterator. Sets the iterator before the first element in
115  * the nodemap.
116  *
117  * @param iterator   Pointer to already allocated iterator memory
118  * @param nodemap       Pointer to the nodemap
119  */
120 void ir_nodemap_iterator_init(ir_nodemap_iterator_t *iterator,
121                               const ir_nodemap_t *nodemap);
122
123 /**
124  * Advances the iterator and returns the current element or NULL if all elements
125  * in the nodemap have been processed.
126  * @attention It is not allowed to use nodemap_insert or nodemap_remove while
127  *            iterating over a nodemap.
128  *
129  * @param iterator  Pointer to the nodemap iterator.
130  * @returns         Next element in the nodemap or NULL
131  */
132 ir_node *ir_nodemap_iterator_next(ir_nodemap_iterator_t *iterator);
133
134 /**
135  * Removes the element the iterator currently points to
136  *
137  * @param nodemap   Pointer to the nodemap
138  * @param iterator  Pointer to the nodemap iterator.
139  */
140 void ir_nodemap_remove_iterator(ir_nodemap_t *nodemap,
141                                 const ir_nodemap_iterator_t *iterator);
142 #endif
143
144 #endif