2 * A lightweight wrapper around pset to store IR nodes.
3 * In some algorithms we want a more deterministic behavior
4 * which the pset_ptr did not guarantee due to it's hash function
9 #include "firm_types.h"
12 typedef struct pset nodeset;
15 * Calculates a hash value for a node.
17 unsigned nodeset_hash(const ir_node *n);
20 * Creates a new nodeset.
22 * @param slots Initial number of collision chains. I.e., #slots
23 * different keys can be hashed without collisions.
28 static INLINE nodeset *new_nodeset(int slots)
30 return new_pset(pset_default_ptr_cmp, slots);
34 * Define some convenience macros.
36 #define new_nodeset_default() new_nodeset(64)
41 * @param nset the nodeset
44 * This does NOT delete the elements of this node set, just it's pointers!
46 static INLINE void del_nodeset(nodeset *nset)
52 * Returns the number of nodes in a nodeset.
54 * @param nset the nodeset
56 static INLINE int nodeset_count(nodeset *nset)
58 return pset_count(nset);
62 * Searches a node in a node set.
64 * @param nset the pset to search in
65 * @param key the node to search
68 * the pointer of the found node in the nodeset or NULL if it was not found
70 static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
72 return (ir_node *) pset_find(nset, key, nodeset_hash(key));
76 * Inserts a node into a pset.
78 * @param nset the nodeset to insert in
79 * @param key a pointer to the element to be inserted
81 * @return a pointer to the inserted element
84 * It is not possible to insert an element more than once. If an element
85 * that should be inserted is already in the set, this functions does
86 * nothing but returning its already existing set_entry.
88 static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
90 return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
94 * Removes a node from a nodeset.
96 * @param nset the nodeset to delete in
97 * @param key a pointer to the element to be deleted
100 * the pointer to the removed element
103 * The current implementation did not allow to remove non-existing elements.
104 * @@@ so, does it do now?
105 * Further, it is allowed to remove elements during an iteration
106 * including the current one.
108 static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
110 return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
114 * Returns the first node of a nodeset.
116 * @param nset the nodeset to iterate
118 * @return a node or NULL if the set is empty
120 static INLINE ir_node *nodeset_first(nodeset *nset)
122 return (ir_node *) pset_first(nset);
126 * Returns the next node of a nodeset.
128 * @param nset the nodeset to iterate
130 * @return a node or NULL if the iteration is finished
132 static INLINE ir_node *nodeset_next(nodeset *nset)
134 return (ir_node *) pset_next(nset);
138 * Breaks the iteration of a set. Must be called before
139 * the next nodeset_first() call if the iteration was NOT
142 * @param nset the nodeset
144 static INLINE void nodeset_break(nodeset *nset)
150 * Iterate over a node set.
152 * @param nset the nodeset
153 * @param irn the iterator node
155 #define foreach_nodeset(nset, irn) for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
157 #endif /* _BENODESETS_H */