static void interval_tree_transplant (struct interval_tree *tree,
struct interval_node *source,
struct interval_node *dest);
-static struct interval_generator *
-interval_generator_create (struct interval_tree *);
+static struct itree_iterator *
+itree_iterator_create (struct interval_tree *);
static void interval_tree_insert (struct interval_tree *, struct interval_node *);
static bool null_safe_is_red (struct interval_node *node);
static bool null_safe_is_black (struct interval_node *node);
};
/* State used when iterating interval. */
-struct interval_generator
+struct itree_iterator
{
struct interval_stack *stack;
ptrdiff_t begin;
are limited by the fact we don't allow modifying the tree at the same
time, making the use of nested iterations quite rare anyway.
So we just use a single global iterator instead for now. */
-static struct interval_generator *iter;
+static struct itree_iterator *iter;
static void
itree_init (void)
{
- iter = interval_generator_create (NULL);
+ iter = itree_iterator_create (NULL);
}
struct check_subtree_result
interval_tree_init (struct interval_tree *tree)
{
interval_tree_clear (tree);
- /* tree->iter = interval_generator_create (tree); */
+ /* tree->iter = itree_iterator_create (tree); */
}
#endif
{
eassert (tree->root == ITREE_NULL);
/* if (tree->iter)
- * interval_generator_destroy (tree->iter); */
+ * itree_iterator_destroy (tree->iter); */
xfree (tree);
}
}
bool
-itree_busy_p (void)
+itree_iterator_busy_p (void)
{
return (iter && iter->running);
}
time.
*/
-struct interval_generator *
-interval_tree_iter_start (struct interval_tree *tree,
- ptrdiff_t begin, ptrdiff_t end,
- enum interval_tree_order order,
- const char* file, int line)
+struct itree_iterator *
+itree_iterator_start (struct interval_tree *tree, ptrdiff_t begin,
+ ptrdiff_t end, enum interval_tree_order order,
+ const char *file, int line)
{
- /* struct interval_generator *iter = tree->iter; */
+ /* struct itree_iterator *iter = tree->iter; */
if (iter->running)
{
fprintf (stderr,
/* Stop using the iterator. */
void
-interval_tree_iter_finish (struct interval_generator *iter)
+itree_iterator_finish (struct itree_iterator *iter)
{
eassert (iter->running);
iter->running = false;
/* Allocate a new generator for TREE. */
-static struct interval_generator *
-interval_generator_create (struct interval_tree *tree)
+static struct itree_iterator *
+itree_iterator_create (struct interval_tree *tree)
{
- struct interval_generator *g = xmalloc (sizeof *g);
+ struct itree_iterator *g = xmalloc (sizeof *g);
/* 19 here just avoids starting with a silly-small stack.
FIXME: Since this stack only needs to be about 2*max_depth
in the worst case, we could completely pre-allocate it to something
started; or NULL if there are no more nodes. */
struct interval_node *
-interval_generator_next (struct interval_generator *g)
+itree_iterator_next (struct itree_iterator *g)
{
eassert (g->running);
break;
}
}
- /* Node may have been invalidated by interval_generator_narrow
+ /* Node may have been invalidated by itree_iterator_narrow
after it was pushed: Check if it still intersects. */
} while (node && ! interval_node_intersects (node, g->begin, g->end));
the current one. I.E. it can't grow on either side. */
void
-interval_generator_narrow (struct interval_generator *g,
- ptrdiff_t begin, ptrdiff_t end)
+itree_iterator_narrow (struct itree_iterator *g,
+ ptrdiff_t begin, ptrdiff_t end)
{
eassert (g->running);
eassert (begin >= g->begin);
node.end directly, is while the node is not part of any tree.
NOTE: It is safe to read node.begin and node.end directly, if the
- node came from a generator, because it validates the nodes it
- returns as a side-effect.
+ node came from an iterator, because it validates the nodes it
+ returns as a side-effect. See ITREE_FOREACH.
*/
struct interval_node;
void itree_insert_node (struct interval_tree *tree, struct interval_node *node,
ptrdiff_t begin, ptrdiff_t end);
struct interval_node *interval_tree_remove (struct interval_tree *, struct interval_node *);
-struct interval_generator *interval_tree_iter_start (struct interval_tree *, ptrdiff_t, ptrdiff_t, enum interval_tree_order,
- const char* file, int line);
-void interval_generator_narrow (struct interval_generator *, ptrdiff_t, ptrdiff_t);
-void interval_tree_iter_finish (struct interval_generator *);
-struct interval_node *interval_generator_next (struct interval_generator *);
void interval_tree_insert_gap (struct interval_tree *, ptrdiff_t, ptrdiff_t);
void interval_tree_delete_gap (struct interval_tree *, ptrdiff_t, ptrdiff_t);
-bool itree_busy_p (void);
+
+/* Iteration functions. Almost all code should use ITREE_FOREACH
+ instead. */
+bool itree_iterator_busy_p (void);
+struct itree_iterator *
+itree_iterator_start (struct interval_tree *tree, ptrdiff_t begin,
+ ptrdiff_t end, enum interval_tree_order order,
+ const char *file, int line);
+void itree_iterator_narrow (struct itree_iterator *, ptrdiff_t,
+ ptrdiff_t);
+void itree_iterator_finish (struct itree_iterator *);
+struct interval_node *itree_iterator_next (struct itree_iterator *);
/* Iterate over the intervals between BEG and END in the tree T.
N will hold successive nodes. ORDER can be one of : `ASCENDING`,
if (!t) \
{ } \
else \
- for (struct interval_generator *itree_iter_ \
- = interval_tree_iter_start (t, beg, end, ITREE_##order, \
+ for (struct itree_iterator *itree_iter_ \
+ = itree_iterator_start (t, beg, end, ITREE_##order, \
__FILE__, __LINE__); \
- ((n = interval_generator_next (itree_iter_)) \
- || (interval_tree_iter_finish (itree_iter_), false));)
+ ((n = itree_iterator_next (itree_iter_)) \
+ || (itree_iterator_finish (itree_iter_), false));)
#define ITREE_FOREACH_ABORT() \
- interval_tree_iter_finish (itree_iter_)
+ itree_iterator_finish (itree_iter_)
#define ITREE_FOREACH_NARROW(beg, end) \
- interval_generator_narrow (itree_iter_, beg, end)
+ itree_iterator_narrow (itree_iter_, beg, end)
#endif