diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2013-09-02 11:04:39 +0300 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2013-09-15 11:49:50 +0300 |
commit | c5a22c4344f17169bb20e122e9d935c62aedc063 (patch) | |
tree | cb0fc7a44a7a8fabe9e18e64f5c2e29d5d3d9dfe /include | |
parent | cfe25e2bcada943984e27ee63918fd75dc4563ac (diff) | |
download | qemu-c5a22c4344f17169bb20e122e9d935c62aedc063.zip qemu-c5a22c4344f17169bb20e122e9d935c62aedc063.tar.gz qemu-c5a22c4344f17169bb20e122e9d935c62aedc063.tar.bz2 |
range: add min/max operations on ranges
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/range.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/qemu/range.h b/include/qemu/range.h index 4a0780d..aae9720 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -17,6 +17,24 @@ struct Range { uint64_t end; /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ }; +static inline void range_extend(Range *range, Range *extend_by) +{ + if (!extend_by->begin && !extend_by->end) { + return; + } + if (!range->begin && !range->end) { + *range = *extend_by; + return; + } + if (range->begin > extend_by->begin) { + range->begin = extend_by->begin; + } + /* Compare last byte in case region ends at ~0x0LL */ + if (range->end - 1 < extend_by->end - 1) { + range->end = extend_by->end; + } +} + /* Get last byte of a range from offset + length. * Undefined for ranges that wrap around 0. */ static inline uint64_t range_get_last(uint64_t offset, uint64_t len) |