ROSE 0.11.145.192
|
A container of ranges, somewhat like a set.
The container is able to hold non-overlapping ranges, each of which has some associated value attached to it. Arbitrary ranges can be inserted and erased from the RangeMap without regard to the ranges that are present in the map, since this class can merge and split values (through methods defined on the value) as necessary in order to maintain the non-overlapping invariant. Every attempt was made to optimize this class for storage and execution efficiency and usability. The interface is similar to the std::map interface.
In the simple case, when no data is attached to the ranges in the map, the RangeMap acts somewhat like an std::set with the following differences:
first
member is a Range (the second member is a RangeMapVoid instance with no useful data). Here's an example of using the RangeMap as a set. For every CPU instruction in a binary specimen, it adds the addresses of the instruction to the set. In some architectures, such as x86, the instructions might overlap; this approach correctly handles that.
A more complex example is using a RangeMap to store a value with each range. A simple example follows, where we want to build a RangeMap that associates any address with the function that owns that address, even when functions are discontiguous in the address space. The first step is to define the value type for the RangeMap we'll be using to store this:
Define an AST traversal add each instruction to the RangeMap:
Finally, traverse the AST and print the result. Because RangeMap merges adjacent ranges when possible, the output will contain the fewest number of ranges needed to describe the entire address space that's assigned to functions. Note that it's possible for two or more functions to "own" the same part of the address space if their instructions overlap, but since we defined our RangeMap to hold only one function pointer per address we'll see only the function that was added last for overlapping ranges.
The RangeMap class template can also be specialized to hold more complex values. The value type defines how ranges can be merged and split. RangeMap value types must implement the interface described for RangeMapVoid. Another example of a value type is RangeMapValue, that holds a simple scalar value and determines "mergeabiliy" and "splitability" based on the equality operator. Eventually, MemoryMap might also be rewritten in terms of RangeMap, and will have much more complex rules for merging, splitting, truncating, and removing.
Definition at line 848 of file rangemap.h.
#include <roseSupport/rangemap.h>
Classes | |
struct | RangeCompare |
The value attached to each range in this RangeMap. More... | |
Public Types | |
typedef R | Range |
typedef T | Value |
A type having the Range interface, used as keys in the underlying std::map. | |
typedef Map::iterator | iterator |
typedef Map::const_iterator | const_iterator |
typedef Map::reverse_iterator | reverse_iterator |
typedef Map::const_reverse_iterator | const_reverse_iterator |
Public Member Functions | |
RangeMap () | |
Create a new, empty map. | |
template<class Other > | |
RangeMap (const Other &other) | |
Create a new map from an existing map. | |
bool | empty () const |
Returns true if this RangeMap is empty. | |
size_t | nranges () const |
Returns the number of ranges in the range map. | |
Range::Value | size () const |
Returns the number of values represented by this RangeMap. | |
Range::Value | min () const |
Returns the minimum value in an extent map. | |
Range::Value | max () const |
Returns the maximum value in an extent map. | |
Range | minmax () const |
Returns the range of values in this map. | |
void | clear (bool notify=true) |
Clears the map. | |
void | erase (const Range &erase_range) |
Erases the specified range from this map. | |
template<class OtherMap > | |
void | erase_ranges (const OtherMap &other) |
Erase ranges from this map. | |
iterator | insert (Range new_range, Value new_value=Value(), bool make_hole=true) |
Insert a range/value pair into the map. | |
void | insert_ranges (const RangeMap &x, bool make_hole=true) |
Insert one rangemap into another. | |
void | insert_ranges (const_iterator start, const_iterator stop, bool make_hole=true) |
Insert part of one rangemap into another. | |
bool | overlaps (const RangeMap &x) const |
Determines if two range maps overlap. | |
bool | overlaps (const Range &r) const |
Determines if a range map overlaps with a specified range. | |
bool | distinct (const Range &r) const |
Determines if a range map does not contain any part of the specified range. | |
bool | distinct (const RangeMap &x) const |
Determines if two range maps are distinct. | |
bool | contains (Range need) const |
Determines if this range map contains all of the specified range. | |
bool | contains (const RangeMap &x) const |
Determins if this range map contains all of some other range map. | |
template<class ResultMap > | |
ResultMap | invert () const |
Create an inverse of a range map. | |
template<class ResultMap > | |
ResultMap | invert_within (const Range &limits) const |
Create a range map that's the inverse of some other map. | |
RangeMap | select_overlapping_ranges (const Range &selector) const |
Select ranges overlapping selector range. | |
void | check () const |
void | print (std::ostream &o) const |
Prints unformatted RangeMap on a single line. | |
iterator | begin () |
First-item iterator. | |
const_iterator | begin () const |
First-item iterator. | |
iterator | end () |
End-item iterator. | |
const_iterator | end () const |
End-item iterator. | |
reverse_iterator | rbegin () |
Returns a reverse iterator referring to the last item of the map, the rend() iterator if the RangeMap is empty. | |
const_reverse_iterator | rbegin () const |
Returns a reverse iterator referring to the last item of the map, the rend() iterator if the RangeMap is empty. | |
reverse_iterator | rend () |
Returns a reverse iterator referring to the element right before the first element in the map, which is considered its reverse end. | |
const_reverse_iterator | rend () const |
Returns a reverse iterator referring to the element right before the first element in the map, which is considered its reverse end. | |
iterator | find (const typename Range::Value &addr) |
Find the range containing specified value. | |
const_iterator | find (const typename Range::Value &addr) const |
Find the range containing specified value. | |
iterator | lower_bound (const typename Range::Value &addr) |
Finds the first range ending above the specified value. | |
const_iterator | lower_bound (const typename Range::Value &addr) const |
Finds the first range ending above the specified value. | |
iterator | find_prior (const typename Range::Value &addr) |
Finds the last range starting at or below the specified value. | |
const_iterator | find_prior (const typename Range::Value &addr) const |
Finds the last range starting at or below the specified value. | |
iterator | best_fit (const typename Range::Value &size, iterator start) |
Find range with closest size. | |
const_iterator | best_fit (const typename Range::Value &size, const_iterator start) const |
Find range with closest size. | |
iterator | first_fit (const typename Range::Value &size, iterator start) |
Find first range of larger size. | |
const_iterator | first_fit (const typename Range::Value &size, const_iterator start) |
Find first range of larger size. | |
iterator | find_overlap (const RangeMap &x) |
Find the first overlap between two RangeMap objects. | |
const_iterator | first_overlap (const RangeMap &x) const |
Find the first overlap between two RangeMap objects. | |
iterator | find_overlap (iterator start, iterator stop, const RangeMap &x) |
Find an overlap between two RangeMap objects. | |
const_iterator | find_overlap (const_iterator start, const_iterator stop, const RangeMap &x) const |
Find an overlap between two RangeMap objects. | |
Protected Types | |
typedef std::pair< Range, Range > | RangePair |
typedef std::pair< Range, Value > | MapPair |
typedef std::map< Range, Value, RangeCompare > | Map |
Protected Attributes | |
Map | ranges |
Definition at line 850 of file rangemap.h.
typedef T RangeMap< R, T >::Value |
A type having the Range interface, used as keys in the underlying std::map.
Definition at line 851 of file rangemap.h.
|
protected |
Definition at line 863 of file rangemap.h.
|
protected |
Definition at line 864 of file rangemap.h.
|
protected |
Definition at line 865 of file rangemap.h.
typedef Map::iterator RangeMap< R, T >::iterator |
Definition at line 869 of file rangemap.h.
typedef Map::const_iterator RangeMap< R, T >::const_iterator |
Definition at line 870 of file rangemap.h.
typedef Map::reverse_iterator RangeMap< R, T >::reverse_iterator |
Definition at line 871 of file rangemap.h.
typedef Map::const_reverse_iterator RangeMap< R, T >::const_reverse_iterator |
Definition at line 872 of file rangemap.h.
|
inline |
Create a new, empty map.
Definition at line 880 of file rangemap.h.
|
inlineexplicit |
Create a new map from an existing map.
Definition at line 884 of file rangemap.h.
References RangeMap< R, T >::insert().
|
inline |
First-item iterator.
Returns an iterator for the first item, or the end iterator if the RangeMap is empty. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 901 of file rangemap.h.
Referenced by RangeMap< R, T >::clear(), RangeMap< R, T >::contains(), Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::first_overlap(), RangeMap< R, T >::insert_ranges(), RangeMap< R, T >::print(), and RangeMap< R, T >::size().
|
inline |
First-item iterator.
Returns an iterator for the first item, or the end iterator if the RangeMap is empty. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 904 of file rangemap.h.
|
inline |
End-item iterator.
Returns an iterator to the one-past-last item of the RangeMap, regardless of whether the range map is empty. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 913 of file rangemap.h.
Referenced by RangeMap< R, T >::best_fit(), RangeMap< R, T >::best_fit(), RangeMap< R, T >::clear(), RangeMap< R, T >::contains(), RangeMap< R, T >::contains(), RangeMap< R, T >::distinct(), RangeMap< R, T >::erase(), Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), RangeMap< R, T >::find(), RangeMap< R, T >::find(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::first_fit(), RangeMap< R, T >::first_fit(), RangeMap< R, T >::first_overlap(), RangeMap< R, T >::insert(), RangeMap< R, T >::insert_ranges(), RangeMap< R, T >::invert_within(), RangeMap< R, T >::overlaps(), RangeMap< R, T >::overlaps(), RangeMap< R, T >::print(), RangeMap< R, T >::select_overlapping_ranges(), and RangeMap< R, T >::size().
|
inline |
End-item iterator.
Returns an iterator to the one-past-last item of the RangeMap, regardless of whether the range map is empty. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 916 of file rangemap.h.
|
inline |
Returns a reverse iterator referring to the last item of the map, the rend() iterator if the RangeMap is empty.
The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 925 of file rangemap.h.
|
inline |
Returns a reverse iterator referring to the last item of the map, the rend() iterator if the RangeMap is empty.
The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 928 of file rangemap.h.
|
inline |
Returns a reverse iterator referring to the element right before the first element in the map, which is considered its reverse end.
Notice that rend() does not refer to the same element as begin(), but to the element right before it. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 938 of file rangemap.h.
|
inline |
Returns a reverse iterator referring to the element right before the first element in the map, which is considered its reverse end.
Notice that rend() does not refer to the same element as begin(), but to the element right before it. The iterator is valid until any operation that changes the RangeMap, such as an insert or erase.
Definition at line 941 of file rangemap.h.
|
inline |
Find the range containing specified value.
Returns an iterator to the Range containing the specified value, or the end() iterator if no such range exists.
Definition at line 950 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
Referenced by RangeMap< R, T >::contains(), and RangeMap< R, T >::insert().
|
inline |
Find the range containing specified value.
Returns an iterator to the Range containing the specified value, or the end() iterator if no such range exists.
Definition at line 956 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
|
inline |
Finds the first range ending above the specified value.
This is similar to the find() method, except it does not return the end() iterator if a range exists above the specified value.
Definition at line 968 of file rangemap.h.
Referenced by RangeMap< R, T >::erase(), RangeMap< R, T >::find(), RangeMap< R, T >::find(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_overlap(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::insert(), RangeMap< R, T >::invert_within(), RangeMap< R, T >::overlaps(), and RangeMap< R, T >::select_overlapping_ranges().
|
inline |
Finds the first range ending above the specified value.
This is similar to the find() method, except it does not return the end() iterator if a range exists above the specified value.
Definition at line 971 of file rangemap.h.
|
inline |
Finds the last range starting at or below the specified value.
Returns the end iterator if there is no range containing a value less than or equal to the specified value.
Definition at line 979 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::empty(), RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
|
inline |
Finds the last range starting at or below the specified value.
Returns the end iterator if there is no range containing a value less than or equal to the specified value.
Definition at line 989 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::empty(), RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
|
inline |
Find range with closest size.
Returns an iterator pointing to the first range at or after the specified start
iterator whose size is at least as large as the specified size. Returns the end iterator if no such range exists. Note that this is an O(N) algorithm.
Definition at line 1006 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::size().
|
inline |
Find range with closest size.
Returns an iterator pointing to the first range at or after the specified start
iterator whose size is at least as large as the specified size. Returns the end iterator if no such range exists. Note that this is an O(N) algorithm.
Definition at line 1016 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::size().
|
inline |
Find first range of larger size.
Returns an iterator to the first range at least as large as the specified size
and at or after start
. Returns the end iterator if no range is found. Note that this is an O(N) algorithm.
Definition at line 1032 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::size().
|
inline |
Find first range of larger size.
Returns an iterator to the first range at least as large as the specified size
and at or after start
. Returns the end iterator if no range is found. Note that this is an O(N) algorithm.
Definition at line 1039 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::size().
|
inline |
Returns true if this RangeMap is empty.
Definition at line 1054 of file rangemap.h.
Referenced by RangeMap< R, T >::contains(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::find_prior(), RangeMap< R, T >::max(), and RangeMap< R, T >::min().
|
inline |
|
inline |
Returns the number of values represented by this RangeMap.
The number of values does not typically correlate with the amount of memory used by the RangeMap since each element of the underlying std::map represents an arbitrary number of values. Note that if the range occupies the entire possible set of values then the size might be returned as zero due to overflow, and it will be necessary to call empty() to make the determination.
Definition at line 1068 of file rangemap.h.
References RangeMap< R, T >::begin(), and RangeMap< R, T >::end().
Referenced by RangeMap< R, T >::best_fit(), RangeMap< R, T >::best_fit(), RangeMap< R, T >::first_fit(), and RangeMap< R, T >::first_fit().
|
inline |
Returns the minimum value in an extent map.
The extent map must not be empty.
Definition at line 1076 of file rangemap.h.
References RangeMap< R, T >::empty().
Referenced by RangeMap< R, T >::minmax().
|
inline |
Returns the maximum value in an extent map.
The extent map must not be empty.
Definition at line 1082 of file rangemap.h.
References RangeMap< R, T >::empty().
Referenced by RangeMap< R, T >::minmax().
Returns the range of values in this map.
Definition at line 1088 of file rangemap.h.
References Range< T >::inin(), RangeMap< R, T >::max(), and RangeMap< R, T >::min().
|
inline |
Clears the map.
Removes all entries from the map. If notify
is true then also call the removing() method of each value.
Definition at line 1105 of file rangemap.h.
References RangeMap< R, T >::begin(), and RangeMap< R, T >::end().
|
inline |
Erases the specified range from this map.
The range to remove can span multiple existing ranges and/or parts of ranges, or no ranges at all. It would be nice to be able to return an iterator to the next item since we have that in hand. Unfortunately, limitations of std::map make this impractical. If you need an iterator, just make another call to lower_bound().
Definition at line 1117 of file rangemap.h.
References Range< T >::begins_after(), Range< T >::contained_in(), Range< T >::contains(), Range< T >::empty(), RangeMap< R, T >::end(), Range< T >::ends_before(), Range< T >::first(), Range< T >::last(), Range< T >::left_of(), RangeMap< R, T >::lower_bound(), and Range< T >::split_range_at().
Referenced by RangeMap< R, T >::erase_ranges(), and RangeMap< R, T >::insert().
|
inline |
Erase ranges from this map.
Every range in the other
map is erased from this map. The maps need not be the same type as long as their ranges are the same type. The values of the other
map are not used–only its ranges.
Definition at line 1177 of file rangemap.h.
References RangeMap< R, T >::erase(), and Range< T >::inin().
Referenced by Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping().
|
inline |
Insert a range/value pair into the map.
If make_hole
is true then the new range is allowed to replace existing ranges (or parts thereof), otherwise if the new range conflicts with eixsting ranges the new extent is not inserted and no change is made to the map. If merge
is true then we attempt to merge the new range into adjacent ranges. Returns an iterator to the new map element, or if merged, to the element that contains the new value. Returns the end iterator if the range was not inserted.
Definition at line 1188 of file rangemap.h.
References Range< T >::abuts_gt(), Range< T >::abuts_lt(), Range< T >::empty(), RangeMap< R, T >::end(), RangeMap< R, T >::erase(), Range< T >::erase(), RangeMap< R, T >::find(), Range< T >::first(), Range< T >::join(), Range< T >::last(), RangeMap< R, T >::lower_bound(), Range< T >::maximum(), Range< T >::minimum(), and Range< T >::overlaps().
Referenced by RangeMap< R, T >::RangeMap(), Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), RangeMap< R, T >::insert_ranges(), and RangeMap< R, T >::select_overlapping_ranges().
|
inline |
Insert one rangemap into another.
Definition at line 1220 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::end(), and RangeMap< R, T >::insert_ranges().
Referenced by RangeMap< R, T >::insert_ranges().
|
inline |
Insert part of one rangemap into another.
The ranges from start
(inclusive) to stop
(exclusive) are inserted into this range map. The start
and stop
iterators should not be iterators of this map, but some other.
Definition at line 1227 of file rangemap.h.
References RangeMap< R, T >::insert().
|
inline |
Determines if two range maps overlap.
Returns true iff any ranges of this map overlap with any ranges of map x
.
Definition at line 1238 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::first_overlap().
Referenced by RangeMap< R, T >::distinct().
|
inline |
Determines if a range map overlaps with a specified range.
Returns true iff any part of the range r
is present in the map. A RangeMap never overlaps with an empty range.
Definition at line 1244 of file rangemap.h.
References Range< T >::empty(), RangeMap< R, T >::end(), Range< T >::first(), RangeMap< R, T >::lower_bound(), and Range< T >::overlaps().
|
inline |
Determines if a range map does not contain any part of the specified range.
Returns false if any part of the range r
is present in the map. An empty range is always distinct from the map.
Definition at line 1253 of file rangemap.h.
References RangeMap< R, T >::overlaps().
Referenced by Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping().
|
inline |
Determines if two range maps are distinct.
Returns true iff there is no range in this map that overlaps with any range of map x
.
Definition at line 1259 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::first_overlap().
|
inline |
Determines if this range map contains all of the specified range.
If the specified range is empty then this function returns true: the map contains all empty ranges.
Definition at line 1265 of file rangemap.h.
References Range< T >::begins_before(), Range< T >::empty(), RangeMap< R, T >::end(), Range< T >::ends_before(), RangeMap< R, T >::find(), Range< T >::first(), Range< T >::overlaps(), and Range< T >::split_range_at().
Referenced by RangeMap< R, T >::contains().
|
inline |
Determins if this range map contains all of some other range map.
Returns true iff each range in x
is contained in some range of this map. If x
is empty this function returns true: a RangeMap contains all empty ranges.
Definition at line 1286 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::contains(), RangeMap< R, T >::empty(), and RangeMap< R, T >::end().
|
inline |
Find the first overlap between two RangeMap objects.
Returns an iterator for this map that points to the first range that overlaps with some range in the other map, x
. Returns the end iterator if no overlap is found.
Definition at line 1305 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::end(), and RangeMap< R, T >::find_overlap().
Referenced by RangeMap< R, T >::find_overlap(), and RangeMap< R, T >::first_overlap().
|
inline |
Find the first overlap between two RangeMap objects.
Returns an iterator for this map that points to the first range that overlaps with some range in the other map, x
. Returns the end iterator if no overlap is found.
Definition at line 1308 of file rangemap.h.
References RangeMap< R, T >::begin(), RangeMap< R, T >::end(), and RangeMap< R, T >::find_overlap().
Referenced by RangeMap< R, T >::distinct(), and RangeMap< R, T >::overlaps().
|
inline |
Find an overlap between two RangeMap objects.
Returns an iterator for this map that points to the first range that overlaps with some range in the other map, x
. The returned iterator will be between start
(inclusive) and stop
(exclusive), which must obviously be iterators for this RangeMap, not x
. Returns the end iterator if there is no overlap within the restricted ranges.
Definition at line 1319 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
|
inline |
Find an overlap between two RangeMap objects.
Returns an iterator for this map that points to the first range that overlaps with some range in the other map, x
. The returned iterator will be between start
(inclusive) and stop
(exclusive), which must obviously be iterators for this RangeMap, not x
. Returns the end iterator if there is no overlap within the restricted ranges.
Definition at line 1334 of file rangemap.h.
References RangeMap< R, T >::end(), and RangeMap< R, T >::lower_bound().
|
inline |
Create an inverse of a range map.
The values of the result are default constructed.
Definition at line 1358 of file rangemap.h.
References Range< T >::all().
|
inline |
Create a range map that's the inverse of some other map.
The returned map's ranges will be limited according to the specified limits
. The values of the result are default constructed.
Definition at line 1365 of file rangemap.h.
References Range< T >::empty(), RangeMap< R, T >::end(), Range< T >::first(), Range< T >::inin(), Range< T >::last(), Range< T >::left_of(), and RangeMap< R, T >::lower_bound().
|
inline |
Select ranges overlapping selector range.
Returns a new range map whose ranges are those ranges of this map that overlap with the specified selector
range.
Definition at line 1384 of file rangemap.h.
References Range< T >::empty(), RangeMap< R, T >::end(), RangeMap< R, T >::insert(), Range< T >::left_of(), RangeMap< R, T >::lower_bound(), and Range< T >::overlaps().
|
inline |
Definition at line 1400 of file rangemap.h.
|
inline |
Prints unformatted RangeMap on a single line.
Definition at line 1480 of file rangemap.h.
References RangeMap< R, T >::begin(), and RangeMap< R, T >::end().
Definition at line 866 of file rangemap.h.