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 #ifndef _FIRM_IRNODEHASHMAP_H_
28 #define _FIRM_IRNODEHASHMAP_H_
32 typedef struct ir_nodehashmap_entry_t {
35 } ir_nodehashmap_entry_t;
37 #define HashSet ir_nodehashmap_t
38 #define HashSetIterator ir_nodehashmap_iterator_t
39 #define ValueType ir_nodehashmap_entry_t
44 #undef HashSetIterator
47 typedef struct ir_nodehashmap_t ir_nodehashmap_t;
48 typedef struct ir_nodehashmap_iterator_t ir_nodehashmap_iterator_t;
51 * Initializes a nodehashmap with default size.
53 * @param nodehashmap Pointer to allocated space for the nodehashmap
55 void ir_nodehashmap_init(ir_nodehashmap_t *nodehashmap);
58 * Initializes a nodehashmap
60 * @param nodehashmap Pointer to allocated space for the nodehashmap
61 * @param expected_elements Number of elements expected in the nodehashmap
64 void ir_nodehashmap_init_size(ir_nodehashmap_t *nodehashmap,
65 size_t expected_elements);
68 * Destroys a nodehashmap and frees the memory allocated for hashtable. The
69 * memory of the nodehashmap itself is not freed.
71 * @param nodehashmap Pointer to the nodehashmap
73 void ir_nodehashmap_destroy(ir_nodehashmap_t *nodehashmap);
76 * Inserts a node into a nodehashmap.
78 * @param nodehashmap Pointer to the nodehashmap
79 * @param node node to insert into the nodehashmap
80 * @param data data to associate with the node
82 void ir_nodehashmap_insert(ir_nodehashmap_t *nodehashmap, ir_node *node,
86 * Removes a node from a nodehashmap. Does nothing if the nodehashmap doesn't
89 * @param nodehashmap Pointer to the nodehashmap
90 * @param node Node to remove from the nodehashmap
92 void ir_nodehashmap_remove(ir_nodehashmap_t *nodehashmap, const ir_node *node);
95 * Tests whether a nodehashmap contains a specific node
97 * @param nodehashmap Pointer to the nodehashmap
98 * @param node The pointer to find
99 * @returns the associated data of the node or NULL
101 void *ir_nodehashmap_get(const ir_nodehashmap_t *nodehashmap,
102 const ir_node *node);
104 #define ir_nodehashmap_get(type, self, node) ((type*)ir_nodehashmap_get((self), (node)))
107 * Returns the number of pointers contained in the nodehashmap
109 * @param nodehashmap Pointer to the nodehashmap
110 * @returns Number of pointers contained in the nodehashmap
112 size_t ir_nodehashmap_size(const ir_nodehashmap_t *nodehashmap);
115 * Initializes a nodehashmap iterator. Sets the iterator before the first
116 * element in the nodehashmap.
118 * @param iterator Pointer to already allocated iterator memory
119 * @param nodehashmap Pointer to the nodehashmap
121 void ir_nodehashmap_iterator_init(ir_nodehashmap_iterator_t *iterator,
122 const ir_nodehashmap_t *nodehashmap);
125 * Advances the iterator and returns the current element or NULL if all elements
126 * in the nodehashmap have been processed.
127 * @attention It is not allowed to use nodehashmap_insert or nodehashmap_remove
128 * while iterating over a nodehashmap.
130 * @param iterator Pointer to the nodehashmap iterator.
131 * @returns Next element in the nodehashmap or NULL
133 ir_nodehashmap_entry_t ir_nodehashmap_iterator_next(
134 ir_nodehashmap_iterator_t *iterator);
137 * Removes the element the iterator currently points to
139 * @param nodehashmap Pointer to the nodehashmap
140 * @param iterator Pointer to the nodehashmap iterator.
142 void ir_nodehashmap_remove_iterator(ir_nodehashmap_t *nodehashmap,
143 const ir_nodehashmap_iterator_t *iterator);
145 #define foreach_ir_nodehashmap(nodehashmap, entry, iter) \
146 for (ir_nodehashmap_iterator_init(&iter, nodehashmap), \
147 entry = ir_nodehashmap_iterator_next(&iter); \
148 entry.node != NULL; entry = ir_nodehashmap_iterator_next(&iter))