Class DynamicIntArray

java.lang.Object
ai.timefold.solver.core.impl.util.DynamicIntArray

public final class DynamicIntArray extends Object
A class representing an int array that is dynamically allocated based on the first set index. The array is only created when the first element is set and is reallocated as needed when lower indices are accessed.
  • Constructor Details

  • Method Details

    • set

      public void set(int index, int value)
      Sets the value at the specified index. If this is the first element, the array is created. If the index is lower than the current firstIndex or higher than the current lastIndex, the array is reallocated with a growth strategy to reduce frequent reallocations.
      Parameters:
      index - the index at which to set the value
      value - the value to set
    • get

      public int get(int index)
      Gets the value at the specified index.
      Parameters:
      index - the index from which to get the value
      Returns:
      the value at the index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • clear

      public void clear()
      Clears the array by setting all values to 0. The array structure is preserved, only the values are reset.