Package ghidra.util.map

# Class ValueMap<T>

java.lang.Object
ghidra.util.map.ValueMap<T>

Type Parameters:
  `T` - data value type

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `IntValueMap`, `ObjectValueMap`

public abstract class ValueMap<T> extends Object implements Serializable
Base class for managing data values that are accessed by an ordered long index key. Specific data value types are determined by the derived class.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final NoValueException`
  `noValueException`
  `protected int`
  `numProperties`
  `protected short`
  `pageSize`
  `protected ghidra.util.map.ValueStoragePageIndex`
  `propertyPageIndex`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `ValueMap(String name, int numPageBits, Class<T> objectClass)`
  Construct a PropertyMap
  `protected`
  `ValueMap(String name, Class<T> objectClass)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract int`
  `getDataSize()`
  Returns the size (in bytes) of the data that is stored in this property set.
  `long`
  `getFirstPropertyIndex()`
  Get the first index where a property value exists.
  `protected final long`
  `getIndex(long pageID, short offset)`
  Create an index from the pageID and the offset in the page.
  `long`
  `getLastPropertyIndex()`
  Get the last index where a property value exists.
  `String`
  `getName()`
  Get the name for this property manager.
  `long`
  `getNextPropertyIndex(long index)`
  Get the next index where the property value exists.
  `Class<T>`
  `getObjectClass()`
  Returns property object class associated with this set.
  `protected ghidra.util.map.ValueStoragePage<T>`
  `getOrCreatePage(long pageID)`
  `protected ghidra.util.map.ValueStoragePage<T>`
  `getPage(long pageId)`
  `protected final long`
  `getPageID(long index)`
  Extract the page ID from the given index.
  `protected final short`
  `getPageOffset(long index)`
  Extract the page offset from the given index.
  `long`
  `getPreviousPropertyIndex(long index)`
  Get the previous index where a property value exists.
  `LongIterator`
  `getPropertyIterator()`
  Returns an iterator over the indices having the given property value.
  `LongIterator`
  `getPropertyIterator(long start)`
  Returns an iterator over the indices having the given property value.
  `LongIterator`
  `getPropertyIterator(long start, boolean before)`
  Returns an iterator over the indices having the given property value.
  `LongIterator`
  `getPropertyIterator(long start, long end)`
  Creates an iterator over all the indexes that have this property within the given range.
  `LongIterator`
  `getPropertyIterator(long start, long end, boolean atStart)`
  Creates an iterator over all the indexes that have this property within the given range.
  `int`
  `getSize()`
  Get the number of properties in the set.
  `boolean`
  `hasProperty(long index)`
  returns whether there is a property value at index.
  `boolean`
  `intersects(long start, long end)`
  Given two indices it indicates whether there is an index in that range (inclusive) having the property.
  `protected abstract void`
  `moveIndex(long from, long to)`
  `void`
  `moveRange(long start, long end, long newStart)`
  Move the range of properties to the newStart index.
  `boolean`
  `remove(long index)`
  Remove the property value at the given index.
  `boolean`
  `removeRange(long start, long end)`
  Removes all property values within a given range.
  `void`
  `restoreProperties(ObjectInputStream ois)`
  Restores all the properties from the input stream.
  `protected abstract void`
  `restoreProperty(ObjectInputStream ois, long addr)`
  `void`
  `saveProperties(ObjectOutputStream oos, long start, long end)`
  Saves all property values between start and end to the output stream
  `protected abstract void`
  `saveProperty(ObjectOutputStream oos, long addr)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### noValueException

    protected static final NoValueException noValueException

  - ### propertyPageIndex

    protected ghidra.util.map.ValueStoragePageIndex propertyPageIndex

  - ### pageSize

    protected short pageSize

  - ### numProperties

    protected int numProperties

- ## Constructor Details

  - ### ValueMap

    protected ValueMap(String name, Class<T> objectClass)

  - ### ValueMap

    protected ValueMap(String name, int numPageBits, Class<T> objectClass)
    Construct a PropertyMap
    Parameters:
      `name` - property name
      `numPageBits` - number of bits to use for the page size. Will be set to be at least 8 and no more than 15.
      `objectClass` - saveable property value class

- ## Method Details

  - ### getDataSize

    public abstract int getDataSize()
    Returns the size (in bytes) of the data that is stored in this property set.
    Returns:
      the size (in bytes) of the data that is stored in this property set.

  - ### getName

    public String getName()
    Get the name for this property manager.

  - ### getObjectClass

    public Class<T> getObjectClass()
    Returns property object class associated with this set.

  - ### getPage

    protected ghidra.util.map.ValueStoragePage<T> getPage(long pageId)

  - ### getOrCreatePage

    protected ghidra.util.map.ValueStoragePage<T> getOrCreatePage(long pageID)

  - ### intersects

    public boolean intersects(long start, long end)
    Given two indices it indicates whether there is an index in that range (inclusive) having the property.

    Parameters:
      `start` - the start of the index range.
      `end` - the end of the index range.
    Returns:
      boolean true if at least one index in the range has the property, false otherwise.

  - ### removeRange

    public boolean removeRange(long start, long end)
    Removes all property values within a given range.
    Parameters:
      `start` - begin range
      `end` - end range, inclusive
    Returns:
      true if any property value was removed; return false otherwise.

  - ### remove

    public boolean remove(long index)
    Remove the property value at the given index.
    Parameters:
      `index` - the long representation of an address.
    Returns:
      true if the property value was removed, false otherwise.

  - ### hasProperty

    public boolean hasProperty(long index)
    returns whether there is a property value at index.
    Parameters:
      `index` - the long representation of an address.

  - ### getNextPropertyIndex

    public long getNextPropertyIndex(long index) throws NoSuchIndexException
    Get the next index where the property value exists.
    Parameters:
      `index` - the address from which to begin the search (exclusive).
    Throws:
      `NoSuchIndexException` - thrown if there is no address with a property value after the given address.

  - ### getPreviousPropertyIndex

    public long getPreviousPropertyIndex(long index) throws NoSuchIndexException
    Get the previous index where a property value exists.
    Parameters:
      `index` - the long representation of an address from which to begin the search (exclusive).
    Throws:
      `NoSuchIndexException` - when there is no index with a property value before the given address.

  - ### getFirstPropertyIndex

    public long getFirstPropertyIndex() throws NoSuchIndexException
    Get the first index where a property value exists.
    Throws:
      `NoSuchIndexException` - when there is no property value for any index.

  - ### getLastPropertyIndex

    public long getLastPropertyIndex() throws NoSuchIndexException
    Get the last index where a property value exists.
    Throws:
      `NoSuchIndexException` - thrown if there is no address having the property value.

  - ### getSize

    public int getSize()
    Get the number of properties in the set.
    Returns:
      the number of properties

  - ### getPageID

    protected final long getPageID(long index)
    Extract the page ID from the given index.
    Parameters:
      `index` - the long representation of an address.

  - ### getPageOffset

    protected final short getPageOffset(long index)
    Extract the page offset from the given index.
    Parameters:
      `index` - the long representation of an address.

  - ### getIndex

    protected final long getIndex(long pageID, short offset)
    Create an index from the pageID and the offset in the page.
    Returns:
      the long representation of an address.

  - ### moveRange

    public void moveRange(long start, long end, long newStart)
    Move the range of properties to the newStart index.
    Parameters:
      `start` - the beginning of the property range to move
      `end` - the end of the property range to move
      `newStart` - the new beginning of the property range after the move

  - ### moveIndex

    protected abstract void moveIndex(long from, long to)

  - ### saveProperty

    protected abstract void saveProperty(ObjectOutputStream oos, long addr) throws IOException
    Throws:
      `IOException`

  - ### restoreProperty

    protected abstract void restoreProperty(ObjectInputStream ois, long addr) throws IOException, ClassNotFoundException
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### getPropertyIterator

    public LongIterator getPropertyIterator(long start, long end)
    Creates an iterator over all the indexes that have this property within the given range.
    Parameters:
      `start` - The start address to search
      `end` - The end address to search
    Returns:
      LongIterator Iterator over indexes that have properties.

  - ### getPropertyIterator

    public LongIterator getPropertyIterator(long start, long end, boolean atStart)
    Creates an iterator over all the indexes that have this property within the given range.
    Parameters:
      `start` - The start address to search
      `end` - The end address to search
      `atStart` - indicates if the iterator should begin at the start address, otherwise it will start at the last address. Set this flag to false if you want to iterate backwards through the properties.
    Returns:
      LongIterator Iterator over indexes that have properties.

  - ### getPropertyIterator

    public LongIterator getPropertyIterator()
    Returns an iterator over the indices having the given property value.

  - ### getPropertyIterator

    public LongIterator getPropertyIterator(long start)
    Returns an iterator over the indices having the given property value.
    Parameters:
      `start` - the starting index for the iterator.

  - ### getPropertyIterator

    public LongIterator getPropertyIterator(long start, boolean before)
    Returns an iterator over the indices having the given property value.
    Parameters:
      `start` - the starting index for the iterator.
      `before` - if true the iterator will be positioned before the start value.

  - ### saveProperties

    public void saveProperties(ObjectOutputStream oos, long start, long end) throws IOException
    Saves all property values between start and end to the output stream
    Parameters:
      `oos` - the output stream
      `start` - the first index in the range to save.
      `end` - the last index in the range to save.
    Throws:
      `IOException` - if an I/O error occurs on the write.

  - ### restoreProperties

    public void restoreProperties(ObjectInputStream ois) throws IOException, ClassNotFoundException
    Restores all the properties from the input stream. Any existing properties will first be removed.
    Parameters:
      `ois` - the input stream.
    Throws:
      `IOException` - if I/O error occurs.
      `ClassNotFoundException` - if the a class cannot be determined for the property value.