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);
36 * @param nset the nodeset
39 * This does NOT delete the elements of this node set, just it's pointers!
41 static INLINE void del_nodeset(nodeset *nset)
47 * Returns the number of nodes in a nodeset.
49 * @param nset the nodeset
51 static INLINE int nodeset_count(nodeset *nset)
53 return pset_count(nset);
57 * Searches a node in a node set.
59 * @param nset the pset to search in
60 * @param key the node to search
63 * the pointer of the found node in the nodeset or NULL if it was not found
65 static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
67 return (ir_node *) pset_find(nset, key, nodeset_hash(key));
71 * Inserts a node into a pset.
73 * @param nset the nodeset to insert in
74 * @param key a pointer to the element to be inserted
76 * @return a pointer to the inserted element
79 * It is not possible to insert an element more than once. If an element
80 * that should be inserted is already in the set, this functions does
81 * nothing but returning its already existing set_entry.
83 static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
85 return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
89 * Removes a node from a nodeset.
91 * @param nset the nodeset to delete in
92 * @param key a pointer to the element to be deleted
95 * the pointer to the removed element
98 * The current implementation did not allow to remove non-existing elements.
99 * @@@ so, does it do now?
100 * Further, it is allowed to remove elements during an iteration
101 * including the current one.
103 static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
105 return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
109 * Returns the first node of a nodeset.
111 * @param nset the nodeset to iterate
113 * @return a node or NULL if the set is empty
115 static INLINE ir_node *nodeset_first(nodeset *nset)
117 return (ir_node *) pset_first(nset);
121 * Returns the next node of a nodeset.
123 * @param nset the nodeset to iterate
125 * @return a node or NULL if the iteration is finished
127 static INLINE ir_node *nodeset_next(nodeset *nset)
129 return (ir_node *) pset_next(nset);
133 * Breaks the iteration of a set. Must be called before
134 * the next nodeset_first() call if the iteration was NOT
137 * @param nset the nodeset
139 static INLINE void nodeset_break(nodeset *nset)
145 * Iterate over a node set.
147 * @param nset the nodeset
148 * @param irn the iterator node
150 #define foreach_nodeset(nset, irn) for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
152 #endif /* _BENODESETS_H */