1 /* virt-bmap examiner plugin
2 * Copyright (C) 2014 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <boost/icl/interval.hpp>
28 #include <boost/icl/interval_set.hpp>
29 #include <boost/icl/interval_map.hpp>
33 /* Maps intervals (uint64_t, uint64_t) to a set of strings, where each
34 * string represents an object that covers that range.
36 typedef set<string> objects;
37 typedef boost::icl::interval_map<uint64_t, objects> ranges;
46 free_ranges (void *mapv)
48 ranges *map = (ranges *) mapv;
53 insert_range (void *mapv, uint64_t start, uint64_t end, const char *object)
55 ranges *map = (ranges *) mapv;
57 obj_set.insert (object);
58 map->add (make_pair (boost::icl::interval<uint64_t>::right_open (start, end),
63 iter_range (void *mapv, void (*f) (uint64_t start, uint64_t end, const char *object, void *opaque), void *opaque)
65 ranges *map = (ranges *) mapv;
66 ranges::iterator iter = map->begin ();
67 while (iter != map->end ()) {
68 boost::icl::interval<uint64_t>::type range = iter->first;
69 uint64_t start = range.lower ();
70 uint64_t end = range.upper ();
72 objects obj_set = iter->second;
73 objects::iterator iter2 = obj_set.begin ();
74 while (iter2 != obj_set.end ()) {
75 f (start, end, iter2->c_str (), opaque);
83 find_range (void *mapv, uint64_t start, uint64_t end, void (*f) (uint64_t start, uint64_t end, const char *object, void *opaque), void *opaque)
85 const ranges *map = (const ranges *) mapv;
87 boost::icl::interval<uint64_t>::type window;
88 window = boost::icl::interval<uint64_t>::right_open (start, end);
90 const ranges r = *map & window;
92 ranges::const_iterator iter = r.begin ();
93 while (iter != r.end ()) {
94 boost::icl::interval<uint64_t>::type range = iter->first;
95 uint64_t start = range.lower ();
96 uint64_t end = range.upper ();
98 objects obj_set = iter->second;
99 objects::iterator iter2 = obj_set.begin ();
100 while (iter2 != obj_set.end ()) {
101 f (start, end, iter2->c_str (), opaque);