Class IntArrayContainer

java.lang.Object
org.tribuo.common.tree.impl.IntArrayContainer

public class IntArrayContainer extends Object
An array container which maintains the array and the size. This class is barely more than a Tuple, it's up to you to maintain the size invariant.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int[]
    The array of ints.
    int
    The number of elements in the array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    IntArrayContainer(int initialCapacity)
    Constructs a new int array container with the specified initial backing array size.
  • Method Summary

    Modifier and Type
    Method
    Description
    int[]
    Returns a copy of the elements in use.
    void
    fill(int[] otherArray)
    Overwrites values from the supplied array into this array.
    void
    Overwrites values in this array with the supplied array.
    void
    grow(int requestedSize)
    Grows the backing array, copying the elements.
    static int[]
    merge(List<int[]> input, IntArrayContainer firstBuffer, IntArrayContainer secondBuffer)
    Merges the list of int arrays into a single int array, using the two supplied buffers.
    static void
    merge(IntArrayContainer input, int[] otherArray, IntArrayContainer output)
    Merges input and otherArray writing to output.
    static void
    removeOther(IntArrayContainer input, int[] otherArray, IntArrayContainer output)
    Copies from input to output excluding the values in otherArray.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • array

      public int[] array
      The array of ints.
    • size

      public int size
      The number of elements in the array.
  • Constructor Details

    • IntArrayContainer

      public IntArrayContainer(int initialCapacity)
      Constructs a new int array container with the specified initial backing array size.
      Parameters:
      initialCapacity - The initial capacity of the backing array.
  • Method Details

    • grow

      public void grow(int requestedSize)
      Grows the backing array, copying the elements.
      Parameters:
      requestedSize - The size to grow the array to.
    • copy

      public int[] copy()
      Returns a copy of the elements in use.
      Returns:
      A copy of the elements.
    • fill

      public void fill(int[] otherArray)
      Overwrites values from the supplied array into this array.
      Parameters:
      otherArray - The array to copy from.
    • fill

      public void fill(IntArrayContainer other)
      Overwrites values in this array with the supplied array.
      Parameters:
      other - The array to copy from.
    • removeOther

      public static void removeOther(IntArrayContainer input, int[] otherArray, IntArrayContainer output)
      Copies from input to output excluding the values in otherArray.

      This assumes both input and otherArray are sorted. Behaviour is undefined if they aren't.

      Parameters:
      input - The input container.
      otherArray - Another (sorted) int array.
      output - The container to write the output to.
    • merge

      public static int[] merge(List<int[]> input, IntArrayContainer firstBuffer, IntArrayContainer secondBuffer)
      Merges the list of int arrays into a single int array, using the two supplied buffers. Requires that all arrays in the list are sorted, and that they contain unique values.
      Parameters:
      input - A list of int arrays.
      firstBuffer - A buffer.
      secondBuffer - Another buffer.
      Returns:
      A sorted array containing all the elements from the input.
    • merge

      public static void merge(IntArrayContainer input, int[] otherArray, IntArrayContainer output)
      Merges input and otherArray writing to output. This assumes both input and otherArray are sorted. Behaviour is undefined if they aren't.
      Parameters:
      input - The input container.
      otherArray - Another (sorted) int array.
      output - The container to write the output to.