Class SortedRangeList

java.lang.Object
ghidra.util.datastruct.SortedRangeList
All Implemented Interfaces:
Iterable<Range>

public class SortedRangeList extends Object implements Iterable<Range>
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

    Constructors
    Constructor
    Description
    Creates 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 Type
    Method
    Description
    void
    addRange(int min, int max)
    Adds the range from min to max to this sorted range list.
    void
     
    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
    Returns the maximum int value in this sorted range list.
    int
    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
     
    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
    Returns true if the range list is empty.
     
    void
    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.
     

    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

      public SortedRangeList(SortedRangeList list)
      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 minimum
      max - the range maximum (inclusive)
    • getRanges

      public Iterator<Range> getRanges()
      Returns an iterator over all the ranges in this list.
      Returns:
      the iterator
    • getRanges

      public Iterator<Range> getRanges(boolean forward)
      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

      public int getMin() throws NoSuchElementException
      Returns the minimum int value in this sorted range list.
      Returns:
      the min value
      Throws:
      NoSuchElementException - if the list is empty.
    • getMax

      public int getMax() throws NoSuchElementException
      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 value
      max - 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

      public Range getRange(int index)
      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

      public void remove(SortedRangeList other)
      Removes all the ranges that are in the specified other list from this list.
      Parameters:
      other - the other sorted range list.
    • intersect

      public SortedRangeList intersect(SortedRangeList other)
      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

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      public Iterator<Range> iterator()
      Specified by:
      iterator in interface Iterable<Range>
    • clear

      public void clear()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object