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