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(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 #define new_nodeset(slots) new_pset(pset_default_ptr_cmp, (slots))
33 * @param nset the nodeset
36 * This does NOT delete the elements of this node set, just it's pointers!
38 #define del_nodeset(nset) del_pset(nset)
41 * Returns the number of nodes in a nodeset.
43 * @param nset the nodeset
45 #define nodeset_count(nset) pset_count(nset)
48 * Searches a node in a node set.
50 * @param nset the pset to search in
51 * @param key the node to search
54 * the pointer of the found node in the nodeset or NULL if it was not found
56 #define nodeset_find(nset, key) (ir_node *)pset_find((nset), (key), nodeset_hash(key))
59 * Inserts a node into a pset.
61 * @param nset the nodeset to insert in
62 * @param key a pointer to the element to be inserted
64 * @return a pointer to the inserted element
67 * It is not possible to insert an element more than once. If an element
68 * that should be inserted is already in the set, this functions does
69 * nothing but returning its already existing set_entry.
71 #define nodeset_insert(nset, key) (ir_node *)pset_insert((nset), (key), nodeset_hash(key))
74 * Removes a node from a nodeset.
76 * @param nset the nodeset to delete in
77 * @param key a pointer to the element to be deleted
80 * the pointer to the removed element
83 * The current implementation did not allow to remove non-existing elements.
84 * @@@ so, does it do now?
85 * Further, it is allowed to remove elements during an iteration
86 * including the current one.
88 #define nodeset_remove(nset, key) (ir_node *)pset_remove((nset), (key), nodeset_hash(key))
91 * Returns the first node of a nodeset.
93 * @param nset the nodeset to iterate
95 * @return a node or NULL if the set is empty
97 #define nodeset_first(nset) (ir_node *)pset_first(nset)
100 * Returns the next node of a nodeset.
102 * @param nset the nodeset to iterate
104 * @return a node or NULL if the iteration is finished
106 #define nodeset_next(nset) (ir_node *)pset_next(nset)
109 * Breaks the iteration of a set. Must be called before
110 * the next nodeset_first() call if the iteration was NOT
113 * @param nset the nodeset
115 #define nodeset_break(nset) pset_break(nset)
117 #endif /* _BENODESETS_H */