2 * Copyright (C) 1995-2007 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
21 * A lightweight wrapper around pset to store IR nodes.
22 * In some algorithms we want a more deterministic behavior
23 * which the pset_ptr did not guarantee due to it's hash function
28 #include "firm_types.h"
31 typedef struct pset nodeset;
34 * Calculates a hash value for a node.
36 unsigned nodeset_hash(const ir_node *n);
39 * Creates a new nodeset.
41 * @param slots Initial number of collision chains. I.e., #slots
42 * different keys can be hashed without collisions.
47 static INLINE nodeset *new_nodeset(int slots)
49 return new_pset(pset_default_ptr_cmp, slots);
53 * Define some convenience macros.
55 #define new_nodeset_default() new_nodeset(64)
60 * @param nset the nodeset
63 * This does NOT delete the elements of this node set, just it's pointers!
65 static INLINE void del_nodeset(nodeset *nset)
71 * Returns the number of nodes in a nodeset.
73 * @param nset the nodeset
75 static INLINE int nodeset_count(nodeset *nset)
77 return pset_count(nset);
81 * Searches a node in a node set.
83 * @param nset the pset to search in
84 * @param key the node to search
87 * the pointer of the found node in the nodeset or NULL if it was not found
89 static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
91 return (ir_node *) pset_find(nset, key, nodeset_hash(key));
95 * Inserts a node into a pset.
97 * @param nset the nodeset to insert in
98 * @param key a pointer to the element to be inserted
100 * @return a pointer to the inserted element
103 * It is not possible to insert an element more than once. If an element
104 * that should be inserted is already in the set, this functions does
105 * nothing but returning its already existing set_entry.
107 static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
109 return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
113 * Removes a node from a nodeset.
115 * @param nset the nodeset to delete in
116 * @param key a pointer to the element to be deleted
119 * the pointer to the removed element
122 * The current implementation did not allow to remove non-existing elements.
123 * @@@ so, does it do now?
124 * Further, it is allowed to remove elements during an iteration
125 * including the current one.
127 static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
129 return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
133 * Returns the first node of a nodeset.
135 * @param nset the nodeset to iterate
137 * @return a node or NULL if the set is empty
139 static INLINE ir_node *nodeset_first(nodeset *nset)
141 return (ir_node *) pset_first(nset);
145 * Returns the next node of a nodeset.
147 * @param nset the nodeset to iterate
149 * @return a node or NULL if the iteration is finished
151 static INLINE ir_node *nodeset_next(nodeset *nset)
153 return (ir_node *) pset_next(nset);
157 * Breaks the iteration of a set. Must be called before
158 * the next nodeset_first() call if the iteration was NOT
161 * @param nset the nodeset
163 static INLINE void nodeset_break(nodeset *nset)
169 * Iterate over a node set.
171 * @param nset the nodeset
172 * @param irn the iterator node
174 #define foreach_nodeset(nset, irn) for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
176 #endif /* _BENODESETS_H */