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
24 * @brief A nodemap. This should be preferred over a simple pset, because it
25 * tries to guarantee deterministic behavior. (and is faster)
27 * @note Actually the bits to make the behavior deterministic are not
30 #ifndef _FIRM_IRNODEMAP_H_
31 #define _FIRM_IRNODEMAP_H_
35 typedef struct ir_nodemap_entry_t {
40 #define HashSet ir_nodemap_t
41 #define HashSetIterator ir_nodemap_iterator_t
42 #define ValueType ir_nodemap_entry_t
47 #undef HashSetIterator
50 typedef struct ir_nodemap_t ir_nodemap_t;
51 typedef struct ir_nodemap_iterator_t ir_nodemap_iterator_t;
54 * Initializes a nodemap with default size.
56 * @param nodemap Pointer to allocated space for the nodemap
58 void ir_nodemap_init(ir_nodemap_t *nodemap);
61 * Initializes a nodemap
63 * @param nodemap Pointer to allocated space for the nodemap
64 * @param expected_elements Number of elements expected in the nodemap (roughly)
66 void ir_nodemap_init_size(ir_nodemap_t *nodemap, size_t expected_elements);
69 * Destroys a nodemap and frees the memory allocated for hashtable. The memory of
70 * the nodemap itself is not freed.
72 * @param nodemap Pointer to the nodemap
74 void ir_nodemap_destroy(ir_nodemap_t *nodemap);
77 * Inserts a node into a nodemap.
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
83 void ir_nodemap_insert(ir_nodemap_t *nodemap, ir_node *node, void *data);
86 * Removes a node from a nodemap. Does nothing if the nodemap doesn't contain
89 * @param nodemap Pointer to the nodemap
90 * @param node Node to remove from the nodemap
92 void ir_nodemap_remove(ir_nodemap_t *nodemap, const ir_node *node);
95 * Tests whether a nodemap contains a specific node
97 * @param nodemap Pointer to the nodemap
98 * @param node The pointer to find
99 * @returns the associated data of the node or NULL
101 void *ir_nodemap_get(const ir_nodemap_t *nodemap, const ir_node *node);
104 * Returns the number of pointers contained in the nodemap
106 * @param nodemap Pointer to the nodemap
107 * @returns Number of pointers contained in the nodemap
109 size_t ir_nodemap_size(const ir_nodemap_t *nodemap);
112 * Initializes a nodemap iterator. Sets the iterator before the first element in
115 * @param iterator Pointer to already allocated iterator memory
116 * @param nodemap Pointer to the nodemap
118 void ir_nodemap_iterator_init(ir_nodemap_iterator_t *iterator,
119 const ir_nodemap_t *nodemap);
122 * Advances the iterator and returns the current element or NULL if all elements
123 * in the nodemap have been processed.
124 * @attention It is not allowed to use nodemap_insert or nodemap_remove while
125 * iterating over a nodemap.
127 * @param iterator Pointer to the nodemap iterator.
128 * @returns Next element in the nodemap or NULL
130 ir_nodemap_entry_t ir_nodemap_iterator_next(ir_nodemap_iterator_t *iterator);
133 * Removes the element the iterator currently points to
135 * @param nodemap Pointer to the nodemap
136 * @param iterator Pointer to the nodemap iterator.
138 void ir_nodemap_remove_iterator(ir_nodemap_t *nodemap,
139 const ir_nodemap_iterator_t *iterator);
141 #define foreach_ir_nodemap(nodemap, entry, iter) \
142 for (ir_nodemap_iterator_init(&iter, nodemap), \
143 entry = ir_nodemap_iterator_next(&iter); \
144 entry.node != NULL; entry = ir_nodemap_iterator_next(&iter))