From ffc83de3572f96c484b199d743ed4fbf8ce1caba Mon Sep 17 00:00:00 2001 From: Michel Lespinasse Date: Sat, 24 Nov 2012 18:44:23 -0800 Subject: [PATCH] kvm tools: rb_int_search_single simplification As the rbtree intervals are not overlapping, rb_int_search_single can trivially be implemented without making use of the max_high field. Signed-off-by: Michel Lespinasse Signed-off-by: Pekka Enberg --- util/rbtree-interval.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/util/rbtree-interval.c b/util/rbtree-interval.c index fd69252..740ff0d 100644 --- a/util/rbtree-interval.c +++ b/util/rbtree-interval.c @@ -5,27 +5,19 @@ struct rb_int_node *rb_int_search_single(struct rb_root *root, u64 point) { struct rb_node *node = root->rb_node; - struct rb_node *lowest = NULL; while (node) { struct rb_int_node *cur = rb_int(node); - if (node->rb_left && (rb_int(node->rb_left)->max_high > point)) { + if (point < cur->low) node = node->rb_left; - } else if (cur->low <= point && cur->high > point) { - lowest = node; - break; - } else if (point > cur->low) { + else if (cur->high <= point) node = node->rb_right; - } else { - break; - } + else + return cur; } - if (lowest == NULL) - return NULL; - - return rb_int(lowest); + return NULL; } struct rb_int_node *rb_int_search_range(struct rb_root *root, u64 low, u64 high)