3 * @author Matthias Braun
5 * @brief A nodeset. This should be prefered over a simple pset, because it
6 * tries to guarantee deterministic behavior. (and is faster)
9 #ifndef _FIRM_IRNODESET_H_
10 #define _FIRM_IRNODESET_H_
14 #define HashSet ir_nodeset_t
15 #define HashSetIterator ir_nodeset_iterator_t
16 #define ValueType ir_node*
21 #undef HashSetIterator
25 * Initializes a nodeset
27 * @param nodeset Pointer to allocated space for the nodeset
29 void ir_nodeset_init(ir_nodeset_t *nodeset);
32 * Initializes a nodeset
34 * @param nodeset Pointer to allocated space for the nodeset
35 * @param expected_elements Number of elements expected in the nodeset (rougly)
37 void ir_nodeset_init_size(ir_nodeset_t *nodeset, size_t expected_elements);
40 * Destroys a nodeset and frees the memory allocated for hashtable. The memory of
41 * the nodeset itself is not freed.
43 * @param nodeset Pointer to the nodeset
45 void ir_nodeset_destroy(ir_nodeset_t *nodeset);
48 * Inserts a node into a nodeset.
50 * @param nodeset Pointer to the nodeset
51 * @param node node to insert into the nodeset
52 * @returns 1 if the element has been inserted,
53 * 0 if it was already there
55 int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node);
58 * Removes a node from a nodeset. Does nothing if the nodeset doesn't contain
61 * @param nodeset Pointer to the nodeset
62 * @param node Node to remove from the nodeset
64 void ir_nodeset_remove(ir_nodeset_t *nodeset, const ir_node *node);
67 * Tests whether a nodeset contains a specific node
69 * @param nodeset Pointer to the nodeset
70 * @param node The pointer to find
71 * @returns 1 if nodeset contains the node, 0 else
73 int ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node);
76 * Returns the number of pointers contained in the nodeset
78 * @param nodeset Pointer to the nodeset
79 * @returns Number of pointers contained in the nodeset
81 size_t ir_nodeset_size(const ir_nodeset_t *nodeset);
84 * Initializes a nodeset iterator. Sets the iterator before the first element in
87 * @param iterator Pointer to already allocated iterator memory
88 * @param nodeset Pointer to the nodeset
90 void ir_nodeset_iterator_init(ir_nodeset_iterator_t *iterator,
91 const ir_nodeset_t *nodeset);
94 * Advances the iterator and returns the current element or NULL if all elements
95 * in the nodeset have been processed.
96 * @attention It is not allowed to use nodeset_insert or nodeset_remove while
97 * iterating over a nodeset.
99 * @param iterator Pointer to the nodeset iterator.
100 * @returns Next element in the nodeset or NULL
102 ir_node *ir_nodeset_iterator_next(ir_nodeset_iterator_t *iterator);
105 * Removes the element the iterator currently points to
107 * @param nodeset Pointer to the nodeset
108 * @param iterator Pointer to the nodeset iterator.
110 void ir_nodeset_remove_iterator(ir_nodeset_t *nodeset,
111 const ir_nodeset_iterator_t *iterator);
113 #define foreach_ir_nodeset(nodeset, irn, iter) \
114 for(ir_nodeset_iterator_init(&iter, nodeset), \
115 irn = ir_nodeset_iterator_next(&iter); \
116 irn != NULL; irn = ir_nodeset_iterator_next(&iter))