kvm tools: Add interval red-black tree helper

Interval rb-tree allows to directly store interval ranges
and quickly lookup an overlap with a single point or a range.

The helper is based on the kernel rb-tree implementation
(located in <linux/rbtree.h>) which alows for the augmention
of the classical rb-tree to be used as an interval tree.

Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Sasha Levin
2015-06-01 16:39:43 +01:00
committed by Will Deacon
parent 70b0d7b0d1
commit e358b4fbdb
4 changed files with 131 additions and 0 deletions
+13
View File
@@ -1,3 +1,4 @@
#ifndef KVM__LINUX_KERNEL_H_
#define KVM__LINUX_KERNEL_H_
@@ -23,4 +24,16 @@
(type *)((char *)__mptr - offsetof(type, member)); })
#endif
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#endif