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_map.hpp>
32 /* Maps intervals (uint64_t, uint64_t) to a set of strings, where each
33 * string represents an object that covers that range.
35 typedef set<string> objects;
36 typedef boost::icl::interval_map<uint64_t, objects> ranges;
45 free_ranges (void *mapv)
47 ranges *map = (ranges *) mapv;
52 insert_range (void *mapv, uint64_t start, uint64_t end, const char *object)
54 ranges *map = (ranges *) mapv;
56 obj_set.insert (object);
57 map->add (make_pair (boost::icl::interval<uint64_t>::right_open (start, end),
62 iter_range (void *mapv, void (*f) (uint64_t start, uint64_t end, const char *object, void *opaque), void *opaque)
64 ranges *map = (ranges *) mapv;
65 ranges::iterator iter = map->begin ();
66 while (iter != map->end ()) {
67 boost::icl::interval<uint64_t>::type range = iter->first;
68 uint64_t start = range.lower ();
69 uint64_t end = range.upper ();
71 objects obj_set = iter->second;
72 objects::iterator iter2 = obj_set.begin ();
73 while (iter2 != obj_set.end ()) {
74 f (start, end, iter2->c_str (), opaque);