On Fri 25-05-12 12:17:34, John Stultz wrote:I suspect range-tree isn't a totally accurate name, but IWell, interval tree is a data structure for tracking a set of
couldn't quite make out the difference between range trees
and interval trees, so I just picked one to call it. Do
let me know if you have a better name.
possibly overlapping intervals. Range tree is a data structure tracking
points allowing for fast queries on a set of points contained in a given
range (gets useful and interesting when dimension> 1). Your data structure
is neither so it would be good to have a different name. OTOH there are so
many data structures that it's hard to find a reasonable unused name ;)
+/**'within' isn't really correct, right? It should rather be 'intersecting'.
+ * range_tree_next_in_range - Return the next range in a range_tree still
+ * contained within a specified range.
+ * @root: range_tree rootI think you should document here that the added range must not intersect
+ * @start: range start
+ * @end: range end
+ *
+ */
+struct range_tree_node *range_tree_next_in_range(struct range_tree_node *node,
+ u64 start, u64 end)
+{
+ struct rb_node *next;
+ struct range_tree_node *candidate;
+ if (!node)
+ return NULL;
+ next = rb_next(&node->rb);
+ if (!next)
+ return NULL;
+
+ candidate = container_of(next, struct range_tree_node, rb);
+
+ if ((candidate->start> end) || (candidate->end< start))
+ return NULL;
+
+ return candidate;
+}
+
+/**
+ * range_tree_add - Add a node to a range tree
+ * @root: range tree to be added to
+ * @node: range_tree_node to be added
+ *
+ * Adds a node to the range tree.
with any other range in the tree.