Package ghidra.program.model.address

# Class AddressSet

java.lang.Object
ghidra.program.model.address.AddressSet

All Implemented Interfaces:
  `AddressSetView`, `Iterable<AddressRange>`

Direct Known Subclasses:
  `ExtCodeBlockImpl`, `StubMemory`

public class AddressSet extends Object implements AddressSetView
Class for storing sets of addresses. This implementation uses a red-black tree where each entry node in the tree stores an address range. The key for an entry node is the minimum address of the range and the value is the maximum address of the range.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AddressSet()`
  Create a new empty Address Set.
  `AddressSet(Address addr)`
  Create a new Address containing a single address.
  `AddressSet(AddressFactory factory)`
  Deprecated.
  use `AddressSet()` (will be kept until at least Ghidra 6.2)
  `AddressSet(AddressFactory factory, Address addr)`
  Deprecated.
  use `AddressSet(Address)` (will be kept until at least Ghidra 6.2)
  `AddressSet(AddressFactory factory, AddressRange range)`
  Deprecated.
  use `AddressSet(AddressRange)` (will be kept until at least Ghidra 6.2)
  `AddressSet(AddressFactory factory, Address start, Address end)`
  Deprecated.
  use `AddressSet(Address, Address)` (will be kept until at least Ghidra 6.2)
  `AddressSet(AddressFactory factory, AddressSetView set)`
  Deprecated.
  use `AddressSet(AddressSetView)` (will be kept until at least Ghidra 6.2)
  `AddressSet(AddressRange range)`
  Create a new Address Set from an address range.
  `AddressSet(Address start, Address end)`
  Creates a new Address set containing a single range
  `AddressSet(AddressSetView set)`
  Create a new Address Set from an existing Address Set.
  `AddressSet(Program program, Address start, Address end)`
  Creates a new Address set containing a single range

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `add(Address address)`
  Adds the given address to this set.
  `final void`
  `add(AddressRange range)`
  Add an address range to this set.
  `void`
  `add(Address start, Address end)`
  Adds the range to this set
  `final void`
  `add(AddressSetView addressSet)`
  Add all addresses of the given AddressSet to this set.
  `void`
  `addRange(Address start, Address end)`
  Adds the range to this set
  `void`
  `addRange(Program program, Address start, Address end)`
  Adds a range of addresses to this set.
  `void`
  `clear()`
  Removes all addresses from the set.
  `final boolean`
  `contains(Address address)`
  Test if the address is contained within this set.
  `final boolean`
  `contains(Address start, Address end)`
  Test if the given address range is contained in this set.
  `final boolean`
  `contains(AddressSetView addrSet)`
  Test if the given address set is a subset of this set.
  `final void`
  `delete(AddressRange range)`
  Deletes an address range from this set.
  `final void`
  `delete(Address start, Address end)`
  Deletes a range of addresses from this set
  `final void`
  `delete(AddressSetView addressSet)`
  Delete all addresses in the given AddressSet from this set.
  `void`
  `deleteFromMin(Address toAddr)`
  Delete all addresses from the minimum address in the set up to and including toAddr.
  `final void`
  `deleteRange(Address start, Address end)`
  Deletes a range of addresses from this set
  `void`
  `deleteToMax(Address fromAddr)`
  Delete all addresses starting at the fromAddr to the maximum address in the set.
  `final boolean`
  `equals(Object obj)`
  `Address`
  `findFirstAddressInCommon(AddressSetView set)`
  Finds the first address in this collection that is also in the given addressSet.
  `AddressIterator`
  `getAddresses(boolean forward)`
  Returns an iterator over all addresses in this set.
  `AddressIterator`
  `getAddresses(Address start, boolean forward)`
  Returns an iterator over the addresses in this address set starting at the start address
  `AddressRangeIterator`
  `getAddressRanges()`
  `AddressRangeIterator`
  `getAddressRanges(boolean forward)`
  Returns an iterator over the ranges in the specified order
  `AddressRangeIterator`
  `getAddressRanges(Address start, boolean forward)`
  Returns an iterator of address ranges starting with the range that contains the given address.
  `AddressRange`
  `getFirstRange()`
  Returns the first range in this set or null if the set is empty;
  `AddressRange`
  `getLastRange()`
  Returns the last range in this set or null if the set is empty;
  `Address`
  `getMaxAddress()`
  `Address`
  `getMinAddress()`
  `long`
  `getNumAddresses()`
  `int`
  `getNumAddressRanges()`
  `AddressRange`
  `getRangeContaining(Address address)`
  Returns the range that contains the given address
  `int`
  `hashCode()`
  `final boolean`
  `hasSameAddresses(AddressSetView addrSet)`
  Returns true if the given address set contains the same set of addresses as this set.
  `final AddressSet`
  `intersect(AddressSetView addrSet)`
  Computes the intersection of this address set with the given address set.
  `final AddressSet`
  `intersectRange(Address start, Address end)`
  Computes the intersection of this address set with the given address range.
  `boolean`
  `intersects(Address start, Address end)`
  Determine if the start and end range intersects with the specified address set.
  `boolean`
  `intersects(AddressSetView addrSet)`
  Determine if this address set intersects with the specified address set.
  `boolean`
  `isEmpty()`
  `Iterator<AddressRange>`
  `iterator()`
  Returns an iterator over the address ranges in this address set.
  `Iterator<AddressRange>`
  `iterator(boolean forward)`
  Returns an iterator over the ranges in the specified order
  `Iterator<AddressRange>`
  `iterator(Address start, boolean forward)`
  Returns an iterator of address ranges starting with the range that contains the given address.
  `String`
  `printRanges()`
  Returns a string displaying the ranges in this set.
  `final AddressSet`
  `subtract(AddressSetView addrSet)`
  Computes the difference of this address set with the given address set (this - set).
  `List<AddressRange>`
  `toList()`
  Returns a list of the AddressRanges in this set.
  `final String`
  `toString()`
  `final AddressSet`
  `union(AddressSetView addrSet)`
  Computes the union of this address set with the given address set.
  `AddressSet`
  `xor(AddressSetView addrSet)`
  Computes the exclusive-or of this address set with the given set.

  ### 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

  - ### AddressSet

    public AddressSet()
    Create a new empty Address Set.

  - ### AddressSet

    @Deprecated public AddressSet(AddressFactory factory)
    Deprecated.
    use `AddressSet()` (will be kept until at least Ghidra 6.2)
    Create a new empty Address Set.
    Parameters:
      `factory` - NOT USED.

  - ### AddressSet

    public AddressSet(AddressRange range)
    Create a new Address Set from an address range.
    Parameters:
      `range` - the range of addresses to include in this set.

  - ### AddressSet

    @Deprecated public AddressSet(AddressFactory factory, AddressRange range)
    Deprecated.
    use `AddressSet(AddressRange)` (will be kept until at least Ghidra 6.2)
    Create a new Address Set from an address range.
    Parameters:
      `factory` - NOT USED.
      `range` - the range of addresses to include in this set.

  - ### AddressSet

    public AddressSet(Address start, Address end)
    Creates a new Address set containing a single range
    Parameters:
      `start` - the start address of the range
      `end` - the end address of the range
    Throws:
      `IllegalArgumentException` - if the start and end addresses are in different spaces. To avoid this, use the constructor `AddressSet(Program, Address, Address)`

  - ### AddressSet

    @Deprecated public AddressSet(AddressFactory factory, Address start, Address end)
    Deprecated.
    use `AddressSet(Address, Address)` (will be kept until at least Ghidra 6.2)
    Creates a new Address set containing a single range
    Parameters:
      `start` - the start address of the range
      `end` - the end address of the range
      `factory` - NOT USED.

  - ### AddressSet

    public AddressSet(Program program, Address start, Address end)
    Creates a new Address set containing a single range
    Parameters:
      `start` - the start address of the range
      `end` - the end address of the range
      `program` - the program whose AddressFactory is used to resolve address ranges where the start and end are in different address spaces. If you use the constructor with just the start and end address and the addresses are in different spaces, you would get an IllegalArgumentException.

  - ### AddressSet

    @Deprecated public AddressSet(AddressFactory factory, AddressSetView set)
    Deprecated.
    use `AddressSet(AddressSetView)` (will be kept until at least Ghidra 6.2)
    Create a new Address Set from an existing Address Set.
    Parameters:
      `set` - Existing Address Set to clone.
      `factory` - NOT USED.

  - ### AddressSet

    public AddressSet(AddressSetView set)
    Create a new Address Set from an existing Address Set.
    Parameters:
      `set` - Existing Address Set to clone.

  - ### AddressSet

    @Deprecated public AddressSet(AddressFactory factory, Address addr)
    Deprecated.
    use `AddressSet(Address)` (will be kept until at least Ghidra 6.2)
    Create a new Address containing a single address.
    Parameters:
      `addr` - the address to be included in this address set.
      `factory` - NOT USED.

  - ### AddressSet

    public AddressSet(Address addr)
    Create a new Address containing a single address.
    Parameters:
      `addr` - the address to be included in this address set.

- ## Method Details

  - ### add

    public final void add(Address address)
    Adds the given address to this set.
    Parameters:
      `address` - the address to add

  - ### add

    public final void add(AddressRange range)
    Add an address range to this set.
    Parameters:
      `range` - the range to add.

  - ### add

    public void add(Address start, Address end)
    Adds the range to this set
    Parameters:
      `start` - the start address of the range to add
      `end` - the end address of the range to add

  - ### addRange

    public void addRange(Address start, Address end)
    Adds the range to this set
    Parameters:
      `start` - the start address of the range to add
      `end` - the end address of the range to add
    Throws:
      `IllegalArgumentException` - if the start and end addresses are in different spaces. To avoid this, use the constructor `addRange(Program, Address, Address)`

  - ### addRange

    public void addRange(Program program, Address start, Address end)
    Adds a range of addresses to this set.
    Parameters:
      `program` - program whose AddressFactory is used to resolve address ranges that span multiple address spaces.
      `start` - the start address of the range to add
      `end` - the end address of the range to add

  - ### add

    public final void add(AddressSetView addressSet)
    Add all addresses of the given AddressSet to this set.
    Parameters:
      `addressSet` - set of addresses to add.

  - ### delete

    public final void delete(AddressRange range)
    Deletes an address range from this set.
    Parameters:
      `range` - AddressRange to remove from this set

  - ### delete

    public final void delete(Address start, Address end)
    Deletes a range of addresses from this set
    Parameters:
      `start` - the starting address of the range to be removed
      `end` - the ending address of the range to be removed (inclusive)

  - ### deleteRange

    public final void deleteRange(Address start, Address end)
    Deletes a range of addresses from this set
    Parameters:
      `start` - the starting address of the range to be removed
      `end` - the ending address of the range to be removed

  - ### delete

    public final void delete(AddressSetView addressSet)
    Delete all addresses in the given AddressSet from this set.
    Parameters:
      `addressSet` - set of addresses to remove from this set.

  - ### clear

    public void clear()
    Removes all addresses from the set.

  - ### printRanges

    public String printRanges()
    Returns a string displaying the ranges in this set.
    Returns:
      a string displaying the ranges in this set.

  - ### toList

    public List<AddressRange> toList()
    Returns a list of the AddressRanges in this set.
    Returns:
      a list of the AddressRanges in this set.

  - ### contains

    public final boolean contains(Address address)
    Description copied from interface: `AddressSetView`
    Test if the address is contained within this set.

    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `address` - address to test.
    Returns:
      true if addr exists in the set, false otherwise.

  - ### contains

    public final boolean contains(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Test if the given address range is contained in this set.

    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `start` - the first address in the range.
      `end` - the last address in the range.
    Returns:
      true if entire range is contained within the set, false otherwise.

  - ### contains

    public final boolean contains(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Test if the given address set is a subset of this set.

    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `addrSet` - the set to test.
    Returns:
      true if the entire set is contained within this set, false otherwise.

  - ### hasSameAddresses

    public final boolean hasSameAddresses(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Returns true if the given address set contains the same set of addresses as this set.
    Specified by:
      `hasSameAddresses` in interface `AddressSetView`
    Parameters:
      `addrSet` - the address set to compare.
    Returns:
      true if the given set contains the same addresses as this set.

  - ### equals

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

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### intersects

    public boolean intersects(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Determine if this address set intersects with the specified address set.
    Specified by:
      `intersects` in interface `AddressSetView`
    Parameters:
      `addrSet` - address set to check intersection with.
    Returns:
      true if this set intersects the specified addrSet else false

  - ### intersectRange

    public final AddressSet intersectRange(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Computes the intersection of this address set with the given address range. This method does not modify this address set.
    Specified by:
      `intersectRange` in interface `AddressSetView`
    Parameters:
      `start` - start of range
      `end` - end of range
    Returns:
      AddressSet a new address set that contains all addresses that are contained in both this set and the given range.

  - ### intersect

    public final AddressSet intersect(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the intersection of this address set with the given address set. This method does not modify this address set.
    Specified by:
      `intersect` in interface `AddressSetView`
    Parameters:
      `addrSet` - the address set to intersect with.
    Returns:
      AddressSet a new address set that contains all addresses that are contained in both this set and the given set.

  - ### union

    public final AddressSet union(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the union of this address set with the given address set. This method does not change this address set.
    Specified by:
      `union` in interface `AddressSetView`
    Parameters:
      `addrSet` - The address set to be unioned with this address set.
    Returns:
      AddressSet A new address set which contains all the addresses from both this set and the given set.

  - ### subtract

    public final AddressSet subtract(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the difference of this address set with the given address set (this - set). Note that this is not the same as (set - this). This method does not change this address set.
    Specified by:
      `subtract` in interface `AddressSetView`
    Parameters:
      `addrSet` - the set to subtract from this set.
    Returns:
      AddressSet a new address set which contains all the addresses that are in this set, but not in the given set.

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `AddressSetView`
    Returns:
      true if this set is empty.

  - ### getMinAddress

    public Address getMinAddress()
    Specified by:
      `getMinAddress` in interface `AddressSetView`
    Returns:
      the minimum address for this set. Returns null if the set is empty.

  - ### getMaxAddress

    public Address getMaxAddress()
    Specified by:
      `getMaxAddress` in interface `AddressSetView`
    Returns:
      the maximum address for this set. Returns null if the set is empty.

  - ### getNumAddressRanges

    public int getNumAddressRanges()
    Specified by:
      `getNumAddressRanges` in interface `AddressSetView`
    Returns:
      the number of address ranges in this set.

  - ### iterator

    public Iterator<AddressRange> iterator()
    Description copied from interface: `AddressSetView`
    Returns an iterator over the address ranges in this address set.
    Specified by:
      `iterator` in interface `AddressSetView`
    Specified by:
      `iterator` in interface `Iterable<AddressRange>`

  - ### iterator

    public Iterator<AddressRange> iterator(boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the ranges in the specified order
    Specified by:
      `iterator` in interface `AddressSetView`
    Parameters:
      `forward` - the ranges are returned from lowest to highest, otherwise from highest to lowest
    Returns:
      an iterator over all the addresse ranges in the set.

  - ### iterator

    public Iterator<AddressRange> iterator(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator of address ranges starting with the range that contains the given address. If there is no range containing the start address, then the the first range will be the next range greater than the start address if going forward, otherwise the range less than the start address
    Specified by:
      `iterator` in interface `AddressSetView`
    Parameters:
      `start` - the address the the first range should contain.
      `forward` - true iterators forward, false backwards
    Returns:
      the AddressRange iterator

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges()
    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Returns:
      an iterator over the address ranges in this address set.

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges(boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the ranges in the specified order
    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Parameters:
      `forward` - the ranges are returned from lowest to highest, otherwise from highest to lowest
    Returns:
      an iterator over all the addresse ranges in the set.

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator of address ranges starting with the range that contains the given address. If there is no range containing the start address, then the the first range will be the next range greater than the start address if going forward, otherwise the range less than the start address
    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Parameters:
      `start` - the address the the first range should contain.
      `forward` - true iterators forward, false backwards
    Returns:
      the AddressRange iterator

  - ### getNumAddresses

    public long getNumAddresses()
    Specified by:
      `getNumAddresses` in interface `AddressSetView`
    Returns:
      the number of addresses in this set.

  - ### getAddresses

    public AddressIterator getAddresses(boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over all addresses in this set.
    Specified by:
      `getAddresses` in interface `AddressSetView`
    Parameters:
      `forward` - if true the address are return in increasing order, otherwise in decreasing order.
    Returns:
      an iterator over all addresses in this set.

  - ### getAddresses

    public AddressIterator getAddresses(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the addresses in this address set starting at the start address
    Specified by:
      `getAddresses` in interface `AddressSetView`
    Parameters:
      `start` - address to start iterating at in the address set
      `forward` - if true address are return from lowest to highest, else from highest to lowest
    Returns:
      an iterator over the addresses in this address set starting at the start address

  - ### intersects

    public boolean intersects(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Determine if the start and end range intersects with the specified address set.
    Specified by:
      `intersects` in interface `AddressSetView`
    Parameters:
      `start` - start of range
      `end` - end of range
    Returns:
      true if the given range intersects this address set.

  - ### xor

    public AddressSet xor(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the exclusive-or of this address set with the given set. This method does not modify this address set.
    Specified by:
      `xor` in interface `AddressSetView`
    Parameters:
      `addrSet` - address set to exclusive-or with.
    Returns:
      AddressSet a new address set containing all addresses that are in either this set or the given set, but not in both sets

  - ### toString

    public final String toString()
    Overrides:
      `toString` in class `Object`

  - ### getRangeContaining

    public AddressRange getRangeContaining(Address address)
    Description copied from interface: `AddressSetView`
    Returns the range that contains the given address
    Specified by:
      `getRangeContaining` in interface `AddressSetView`
    Parameters:
      `address` - the address for which to find a range.
    Returns:
      the range that contains the given address.

  - ### getFirstRange

    public AddressRange getFirstRange()
    Description copied from interface: `AddressSetView`
    Returns the first range in this set or null if the set is empty;
    Specified by:
      `getFirstRange` in interface `AddressSetView`
    Returns:
      the first range in this set or null if the set is empty;

  - ### getLastRange

    public AddressRange getLastRange()
    Description copied from interface: `AddressSetView`
    Returns the last range in this set or null if the set is empty;
    Specified by:
      `getLastRange` in interface `AddressSetView`
    Returns:
      the last range in this set or null if the set is empty;

  - ### findFirstAddressInCommon

    public Address findFirstAddressInCommon(AddressSetView set)
    Description copied from interface: `AddressSetView`
    Finds the first address in this collection that is also in the given addressSet.
    Specified by:
      `findFirstAddressInCommon` in interface `AddressSetView`
    Parameters:
      `set` - the addressSet to search for the first (lowest) common address.
    Returns:
      the first address that is contained in this set and the given set.

  - ### deleteFromMin

    public void deleteFromMin(Address toAddr)
    Delete all addresses from the minimum address in the set up to and including toAddr. Addresses less-than-or-equal to specified address based upon `Address` comparison.
    Parameters:
      `toAddr` - only addresses greater than toAddr will be left in the set.

  - ### deleteToMax

    public void deleteToMax(Address fromAddr)
    Delete all addresses starting at the fromAddr to the maximum address in the set. Addresses greater-than-or-equal to specified address based upon `Address` comparison.
    Parameters:
      `fromAddr` - only addresses less than fromAddr will be left in the set.