Class IntArrayContainer
java.lang.Object
org.tribuo.common.tree.impl.IntArrayContainer
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 -
Constructor Summary
ConstructorsConstructorDescriptionIntArrayContainer(int initialCapacity) Constructs a new int array container with the specified initial backing array size. -
Method Summary
Modifier and TypeMethodDescriptionint[]copy()Returns a copy of the elements in use.voidfill(int[] otherArray) Overwrites values from the supplied array into this array.voidfill(IntArrayContainer other) Overwrites values in this array with the supplied array.voidgrow(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 voidmerge(IntArrayContainer input, int[] otherArray, IntArrayContainer output) Merges input and otherArray writing to output.static voidremoveOther(IntArrayContainer input, int[] otherArray, IntArrayContainer output) Copies from input to output excluding the values in otherArray.
-
Field Details
-
array
public int[] arrayThe array of ints. -
size
public int sizeThe 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.Copies in all the other values and sets the length of this array to the length of the other array.
- Parameters:
otherArray- The array to copy from.
-
fill
Overwrites values in this array with the supplied array.Copies in all the other values and sets the length of this array to the length of the other array.
- Parameters:
other- The array to copy from.
-
removeOther
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
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.
-