From: Andreas Politz Date: Fri, 6 Oct 2017 09:59:54 +0000 (+0200) Subject: Add a function collecting all interval nodes X-Git-Tag: emacs-29.0.90~1616^2~406^2~65 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3945c019ecc8bea75bf868bb388fa56881cb82b6;p=emacs.git Add a function collecting all interval nodes * src/itree.c (interval_tree_nodes): New function --- diff --git a/src/itree.c b/src/itree.c index 785c83ab798..f43189cabe7 100644 --- a/src/itree.c +++ b/src/itree.c @@ -404,6 +404,28 @@ interval_tree_validate (struct interval_tree *tree, struct interval_node *node) return node; } +/* Fill memory pointed at via NODES with all nodes of TREE in the + given ORDER. + + The size of NODES must be sufficiently large. + */ + +void +interval_tree_nodes (struct interval_tree *tree, + struct interval_node **nodes, + enum interval_tree_order order) +{ + struct interval_node *node; + + interval_tree_iter_start (tree, PTRDIFF_MIN, PTRDIFF_MAX, order); + while ((node = interval_tree_iter_next (tree))) + { + *nodes = node; + ++nodes; + } + interval_tree_iter_finish (tree); +} + /* Start a generator iterating all intervals in [BEGIN,END) in the given ORDER. Only one iterator per tree can be running at any time. diff --git a/src/itree.h b/src/itree.h index d35c5afc24c..d685a69eb78 100644 --- a/src/itree.h +++ b/src/itree.h @@ -85,4 +85,5 @@ void interval_tree_iter_finish(struct interval_tree *); struct interval_node *interval_tree_iter_next(struct interval_tree *); void interval_tree_insert_gap(struct interval_tree *, ptrdiff_t, ptrdiff_t); void interval_tree_delete_gap(struct interval_tree *, ptrdiff_t, ptrdiff_t); +void interval_tree_nodes (struct interval_tree *tree, struct interval_node **nodes, enum interval_tree_order order); #endif