Package ghidra.util.datastruct
Class SortedRangeList
java.lang.Object
ghidra.util.datastruct.SortedRangeList
Provides a list of integer ranges that are maintained in sorted order. When a range is added
any ranges that overlap or are adjacent to one another will coalesce into a single range.
-
Constructor Summary
ConstructorDescriptionCreates a new empty sorted range list.Creates a new sorted range list with ranges equivalent to those in the specified list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRange
(int min, int max) Adds the range from min to max to this sorted range list.void
clear()
boolean
contains
(int value) Returns true if the value is contained in any ranges within this list.boolean
contains
(int min, int max) Returns true if a single range contains all the values from min to max.boolean
int
getMax()
Returns the maximum int value in this sorted range list.int
getMin()
Returns the minimum int value in this sorted range list.int
Returns the number of ranges in the list.long
Gets the total number of int values in this range.getRange
(int index) Gets the nth range in this list as indicated by the value of index.int
getRangeIndex
(int value) Gets the range index for the range containing the specified value.Returns an iterator over all the ranges in this list.getRanges
(boolean forward) Returns an iterator over all the ranges in this list that iterates in the direction specified.int
hashCode()
intersect
(SortedRangeList other) Creates a new SortedRangeList that is the intersection of this range list and the other range list specified.boolean
intersects
(int min, int max) Returns true if the range from min to max intersects (overlaps) any ranges in this sorted range list.boolean
isEmpty()
Returns true if the range list is empty.iterator()
void
remove
(SortedRangeList other) Removes all the ranges that are in the specified other list from this list.void
removeRange
(int min, int max) Removes the indicated range of values from the list.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SortedRangeList
public SortedRangeList()Creates a new empty sorted range list. -
SortedRangeList
Creates a new sorted range list with ranges equivalent to those in the specified list.- Parameters:
list
- the sorted range list to make an equivalent copy of.
-
-
Method Details
-
addRange
public void addRange(int min, int max) Adds the range from min to max to this sorted range list. If the range is adjacent to or overlaps any other existing ranges, then those ranges will coalesce.- Parameters:
min
- the range minimummax
- the range maximum (inclusive)
-
getRanges
Returns an iterator over all the ranges in this list.- Returns:
- the iterator
-
getRanges
Returns an iterator over all the ranges in this list that iterates in the direction specified.- Parameters:
forward
- true indicates to iterate forward from minimum to maximum range; false indicates backward iteration form maximum to minimum.- Returns:
- the iterator
-
getMin
Returns the minimum int value in this sorted range list.- Returns:
- the min value
- Throws:
NoSuchElementException
- if the list is empty.
-
getMax
Returns the maximum int value in this sorted range list.- Returns:
- the max value
- Throws:
NoSuchElementException
- if the list is empty.
-
getNumRanges
public int getNumRanges()Returns the number of ranges in the list.- Returns:
- the number of ranges
-
removeRange
public void removeRange(int min, int max) Removes the indicated range of values from the list. This will remove any ranges or portion of ranges that overlap the indicated range.- Parameters:
min
- the minimum value for the range to remove.max
- the maximum value for the range to remove.
-
contains
public boolean contains(int value) Returns true if the value is contained in any ranges within this list.- Parameters:
value
- the value to check for.- Returns:
- true if the value is contained in any ranges within this list.
-
contains
public boolean contains(int min, int max) Returns true if a single range contains all the values from min to max.- Parameters:
min
- the minimum valuemax
- the maximum value- Returns:
- true if a single range contains all the values from min to max.
-
getRangeIndex
public int getRangeIndex(int value) Gets the range index for the range containing the specified value.- Parameters:
value
- the value to look for.- Returns:
- the range index or a negative value if the range list doesn't contain the value.
-
getRange
Gets the nth range in this list as indicated by the value of index.- Parameters:
index
- value indicating which nth range to get.- Returns:
- the range or null if there is no such range in this list.
-
getNumValues
public long getNumValues()Gets the total number of int values in this range.- Returns:
- the number of int values.
-
intersects
public boolean intersects(int min, int max) Returns true if the range from min to max intersects (overlaps) any ranges in this sorted range list.- Parameters:
min
- the range minimum value.max
- the range maximum value.- Returns:
- true if the range from min to max intersects (overlaps) any ranges in this sorted range list.
-
isEmpty
public boolean isEmpty()Returns true if the range list is empty.- Returns:
- true if the range list is empty.
-
remove
Removes all the ranges that are in the specified other list from this list.- Parameters:
other
- the other sorted range list.
-
intersect
Creates a new SortedRangeList that is the intersection of this range list and the other range list specified.- Parameters:
other
- the other range list- Returns:
- the new SortedRangeList representing the intersection.
-
toString
-
iterator
-
clear
public void clear() -
hashCode
public int hashCode() -
equals
-