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 behaviour deterministic are not
30 #ifndef _FIRM_IRNODEMAP_H_
31 #define _FIRM_IRNODEMAP_H_
36 typedef struct ir_nodemap_entry_t {
41 #define HashSet ir_nodemap_t
42 #define HashSetIterator ir_nodemap_iterator_t
43 #define ValueType ir_nodemap_entry_t
48 #undef HashSetIterator
51 typedef struct ir_nodemap_t ir_nodemap_t;
52 typedef struct ir_nodemap_iterator_t ir_nodemap_iterator_t;
55 * Initializes a nodemap with default size.
57 * @param nodemap Pointer to allocated space for the nodemap
59 void ir_nodemap_init(ir_nodemap_t *nodemap);
62 * Initializes a nodemap
64 * @param nodemap Pointer to allocated space for the nodemap
65 * @param expected_elements Number of elements expected in the nodemap (roughly)
67 void ir_nodemap_init_size(ir_nodemap_t *nodemap, size_t expected_elements);
70 * Destroys a nodemap and frees the memory allocated for hashtable. The memory of
71 * the nodemap itself is not freed.
73 * @param nodemap Pointer to the nodemap
75 void ir_nodemap_destroy(ir_nodemap_t *nodemap);
78 * Inserts a node into a nodemap.
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
84 void ir_nodemap_insert(ir_nodemap_t *nodemap, const ir_node *node, void *data);
87 * Removes a node from a nodemap. Does nothing if the nodemap doesn't contain
90 * @param nodemap Pointer to the nodemap
91 * @param node Node to remove from the nodemap
93 void ir_nodemap_remove(ir_nodemap_t *nodemap, const ir_node *node);
96 * Tests whether a nodemap contains a specific node
98 * @param nodemap Pointer to the nodemap
99 * @param node The pointer to find
100 * @returns 1 if nodemap contains the node, 0 else
102 void *ir_nodemap_get(const ir_nodemap_t *nodemap, const ir_node *node);
105 * Returns the number of pointers contained in the nodemap
107 * @param nodemap Pointer to the nodemap
108 * @returns Number of pointers contained in the nodemap
110 size_t ir_nodemap_size(const ir_nodemap_t *nodemap);
114 * Initializes a nodemap iterator. Sets the iterator before the first element in
117 * @param iterator Pointer to already allocated iterator memory
118 * @param nodemap Pointer to the nodemap
120 void ir_nodemap_iterator_init(ir_nodemap_iterator_t *iterator,
121 const ir_nodemap_t *nodemap);
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.
129 * @param iterator Pointer to the nodemap iterator.
130 * @returns Next element in the nodemap or NULL
132 ir_node *ir_nodemap_iterator_next(ir_nodemap_iterator_t *iterator);
135 * Removes the element the iterator currently points to
137 * @param nodemap Pointer to the nodemap
138 * @param iterator Pointer to the nodemap iterator.
140 void ir_nodemap_remove_iterator(ir_nodemap_t *nodemap,
141 const ir_nodemap_iterator_t *iterator);