Class BigArrays
Introducing big arrays
A big array is an array-of-arrays representation of an array. The length of a big array
is bounded by SEGMENT_SIZE
* Integer.MAX_VALUE
= 134217728 *
(231 − 1) rather than Integer.MAX_VALUE
. The type of a big array is that
of an array-of-arrays, so a big array of integers is of type int[][]
. Note that
SEGMENT_SIZE
has been chosen so that a single segment is smaller than 231
bytes independently of the data type. It might be enlarged in the future.
If a
is a big array, a[0]
, a[1]
, … are called the
segments of the big array. All segments, except possibly for the last one, are of length
SEGMENT_SIZE
. Given an index i
into a big array, there is an associated
segment and an associated
displacement into that segment. Access to single
members happens by means of accessors (see, e.g., get(int[][], long)
and
set(int[][], long, int)
), but you can also use the methods
segment(long)
/displacement(long)
to access entries manually.
The intended usage of most of the methods of this class is that they will be imported statically: for example,
import static it.unimi.dsi.fastutil.BigArrays.copy; import static it.unimi.dsi.fastutil.BigArrays.get; import static it.unimi.dsi.fastutil.BigArrays.length; import static it.unimi.dsi.fastutil.BigArrays.set;
Dynamic binding will take care of selecting the right method depending on the array type.
Scanning big arrays
You can scan a big array using the following idiomatic form:
for(int s = 0; s < a.length; s++) { final int[] t = a[s]; final int l = t.length; for(int d = 0; d < l; d++) { do something with t[d] } }or using the simpler reversed version:
for(int s = a.length; s-- != 0;) { final int[] t = a[s]; for(int d = t.length; d-- != 0;) { do something with t[d] } }
Inside the inner loop, the original index in a
can be retrieved using
index(segment, displacement)
. You can also use an additional long to
keep track of the index.
Note that caching is essential in making these loops essentially as fast as those scanning standard arrays (as iterations of the outer loop happen very rarely). Using loops of this kind is extremely faster than using a standard loop and accessors.
In some situations, you might want to iterate over a part of a big array having an offset and a length. In this case, the idiomatic loops are as follows:
for(int s = segment(offset); s < segment(offset + length + SEGMENT_MASK); s++) { final int[] t = a[s]; final int l = (int)Math.min(t.length, offset + length - start(s)); for(int d = (int)Math.max(0, offset - start(s)); d < l; d++) { do something with t[d] } }or, in a reversed form,
for(int s = segment(offset + length + SEGMENT_MASK); s-- != segment(offset);) { final int[] t = a[s]; final int b = (int)Math.max(0, offset - start(s)); for(int d = (int)Math.min(t.length, offset + length - start(s)); d-- != b ;) { do something with t[d] } }
Literal big arrays
A literal big array can be easily created by using the suitable type-specific wrap()
method (e.g., wrap(int[])
) around a standard Java literal array.
Atomic big arrays
Limited support is available for atomic big arrays of integers and longs, with a similar syntax.
Atomic big arrays are arrays of instances of
AtomicIntegerArray
or
AtomicLongArray
of length SEGMENT_SIZE
(or less, for
the last segment, as usual) and their size cannot be changed. Some methods from those classes are
available in BigArrays
for atomic big arrays (e.g.,
incrementAndGet(AtomicIntegerArray[], long)
).
Big alternatives
If you find the kind of “bare hands” approach to big arrays not enough
object-oriented, please use big lists based on big arrays (e.g., IntBigArrayBigList
). Big
arrays follow the Java tradition of considering arrays as a “legal
alien”—something in-between an object and a primitive type. This approach lacks the
consistency of a full object-oriented approach, but provides some significant performance gains.
Additional methods
In particular, the ensureCapacity()
, grow()
, trim()
and
setLength()
methods allow to handle arrays much like array lists.
In addition to commodity methods, this class contains BigSwapper
-based implementations of
quicksort and of a stable,
in-place mergesort. These generic
sorting methods can be used to sort any kind of list, but they find their natural usage, for
instance, in sorting big arrays in parallel.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The mask used to compute the displacement associated to an index.static final int
The shift used to compute the segment associated with an index (equivalently, the logarithm of the segment size).static final int
The current size of a segment (227) is the largest size that makes the physical memory allocation for a single segment strictly smaller than 231 bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
add
(byte[][] array, long index, byte incr) Adds the specified increment the element of the given big array of specified index.static void
add
(char[][] array, long index, char incr) Adds the specified increment the element of the given big array of specified index.static void
add
(double[][] array, long index, double incr) Adds the specified increment the element of the given big array of specified index.static void
add
(float[][] array, long index, float incr) Adds the specified increment the element of the given big array of specified index.static void
add
(int[][] array, long index, int incr) Adds the specified increment the element of the given big array of specified index.static void
add
(long[][] array, long index, long incr) Adds the specified increment the element of the given big array of specified index.static void
add
(short[][] array, long index, short incr) Adds the specified increment the element of the given big array of specified index.static int
addAndGet
(AtomicIntegerArray[] array, long index, int value) Atomically adds a value to an element of the given big atomic array, returning the new value.static long
addAndGet
(AtomicLongArray[] array, long index, long value) Atomically adds a value to an element of the given big atomic array, returning the new value.static void
assertBigArray
(boolean[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(byte[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(char[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(double[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(float[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(int[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(long[][] array) Asserts that the provided big array is correct.static void
assertBigArray
(short[][] array) Asserts that the provided big array is correct.static <K> void
assertBigArray
(K[][] array) Asserts that the provided big array is correct.static boolean
compareAndSet
(AtomicIntegerArray[] array, long index, int expected, int value) Atomically sets an element of the given big atomic array of specified index to specified value, given the current value is equal to a given expected value.static boolean
compareAndSet
(AtomicLongArray[] array, long index, long expected, long value) Atomically sets an element of the given big atomic array of specified index to specified value, given the current value is equal to a given expected value.static boolean[][]
copy
(boolean[][] array) Returns a copy of a big array.static void
copy
(boolean[][] srcArray, long srcPos, boolean[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static boolean[][]
copy
(boolean[][] array, long offset, long length) Returns a copy of a portion of a big array.static byte[][]
copy
(byte[][] array) Returns a copy of a big array.static void
copy
(byte[][] srcArray, long srcPos, byte[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static byte[][]
copy
(byte[][] array, long offset, long length) Returns a copy of a portion of a big array.static char[][]
copy
(char[][] array) Returns a copy of a big array.static void
copy
(char[][] srcArray, long srcPos, char[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static char[][]
copy
(char[][] array, long offset, long length) Returns a copy of a portion of a big array.static double[][]
copy
(double[][] array) Returns a copy of a big array.static void
copy
(double[][] srcArray, long srcPos, double[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static double[][]
copy
(double[][] array, long offset, long length) Returns a copy of a portion of a big array.static float[][]
copy
(float[][] array) Returns a copy of a big array.static void
copy
(float[][] srcArray, long srcPos, float[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static float[][]
copy
(float[][] array, long offset, long length) Returns a copy of a portion of a big array.static int[][]
copy
(int[][] array) Returns a copy of a big array.static void
copy
(int[][] srcArray, long srcPos, int[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static int[][]
copy
(int[][] array, long offset, long length) Returns a copy of a portion of a big array.static long[][]
copy
(long[][] array) Returns a copy of a big array.static long[][]
copy
(long[][] array, long offset, long length) Returns a copy of a portion of a big array.static void
copy
(long[][] srcArray, long srcPos, long[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static short[][]
copy
(short[][] array) Returns a copy of a big array.static short[][]
copy
(short[][] array, long offset, long length) Returns a copy of a portion of a big array.static void
copy
(short[][] srcArray, long srcPos, short[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static <K> K[][]
copy
(K[][] array) Returns a copy of a big array.static <K> K[][]
copy
(K[][] array, long offset, long length) Returns a copy of a portion of a big array.static <K> void
copy
(K[][] srcArray, long srcPos, K[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.static void
copyFromBig
(boolean[][] srcArray, long srcPos, boolean[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(byte[][] srcArray, long srcPos, byte[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(char[][] srcArray, long srcPos, char[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(double[][] srcArray, long srcPos, double[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(float[][] srcArray, long srcPos, float[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(int[][] srcArray, long srcPos, int[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(long[][] srcArray, long srcPos, long[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyFromBig
(short[][] srcArray, long srcPos, short[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static <K> void
copyFromBig
(K[][] srcArray, long srcPos, K[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.static void
copyToBig
(boolean[] srcArray, int srcPos, boolean[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(byte[] srcArray, int srcPos, byte[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(char[] srcArray, int srcPos, char[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(double[] srcArray, int srcPos, double[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(float[] srcArray, int srcPos, float[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(int[] srcArray, int srcPos, int[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(long[] srcArray, int srcPos, long[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
copyToBig
(short[] srcArray, int srcPos, short[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static <K> void
copyToBig
(K[] srcArray, int srcPos, K[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.static void
decr
(byte[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(char[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(double[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(float[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(int[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(long[][] array, long index) Decrements the element of the given big array of specified index.static void
decr
(short[][] array, long index) Decrements the element of the given big array of specified index.static int
decrementAndGet
(AtomicIntegerArray[] array, long index) Atomically decrements an element of the given big atomic array, returning the new value.static long
decrementAndGet
(AtomicLongArray[] array, long index) Atomically decrements an element of the given big atomic array, returning the new value.static int
displacement
(long index) Computes the displacement associated with a given index.static boolean[][]
ensureCapacity
(boolean[][] array, long length) Ensures that a big array can contain the given number of entries.static boolean[][]
ensureCapacity
(boolean[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static byte[][]
ensureCapacity
(byte[][] array, long length) Ensures that a big array can contain the given number of entries.static byte[][]
ensureCapacity
(byte[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static char[][]
ensureCapacity
(char[][] array, long length) Ensures that a big array can contain the given number of entries.static char[][]
ensureCapacity
(char[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static double[][]
ensureCapacity
(double[][] array, long length) Ensures that a big array can contain the given number of entries.static double[][]
ensureCapacity
(double[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static float[][]
ensureCapacity
(float[][] array, long length) Ensures that a big array can contain the given number of entries.static float[][]
ensureCapacity
(float[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static int[][]
ensureCapacity
(int[][] array, long length) Ensures that a big array can contain the given number of entries.static int[][]
ensureCapacity
(int[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static long[][]
ensureCapacity
(long[][] array, long length) Ensures that a big array can contain the given number of entries.static long[][]
ensureCapacity
(long[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static short[][]
ensureCapacity
(short[][] array, long length) Ensures that a big array can contain the given number of entries.static short[][]
ensureCapacity
(short[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static <K> K[][]
ensureCapacity
(K[][] array, long length) Ensures that a big array can contain the given number of entries.static <K> K[][]
ensureCapacity
(K[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.static void
ensureFromTo
(boolean[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(byte[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(char[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(double[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(float[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(int[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(long[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureFromTo
(long bigArrayLength, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array of given length.static void
ensureFromTo
(short[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static <K> void
ensureFromTo
(K[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static void
ensureLength
(long bigArrayLength) Ensures that a big-array length is legal.static void
ensureOffsetLength
(boolean[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(byte[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(char[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(double[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(float[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(int[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(long[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureOffsetLength
(long bigArrayLength, long offset, long length) Ensures that a range given by an offset and a length fits a big array of given length.static void
ensureOffsetLength
(short[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static <K> void
ensureOffsetLength
(K[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.static void
ensureSameLength
(boolean[][] a, boolean[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(byte[][] a, byte[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(char[][] a, char[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(double[][] a, double[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(float[][] a, float[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(int[][] a, int[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(long[][] a, long[][] b) Ensures that two big arrays are of the same length.static void
ensureSameLength
(short[][] a, short[][] b) Ensures that two big arrays are of the same length.static <K> void
ensureSameLength
(K[][] a, K[][] b) Ensures that two big arrays are of the same length.static boolean
equals
(boolean[][] a1, boolean[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(byte[][] a1, byte[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(char[][] a1, char[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(double[][] a1, double[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(float[][] a1, float[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(int[][] a1, int[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(long[][] a1, long[][] a2) Returns true if the two big arrays are elementwise equal.static boolean
equals
(short[][] a1, short[][] a2) Returns true if the two big arrays are elementwise equal.static <K> boolean
equals
(K[][] a1, K[][] a2) Returns true if the two big arrays are elementwise equal.static void
fill
(boolean[][] array, boolean value) Fills the given big array with the given value.static void
fill
(boolean[][] array, long from, long to, boolean value) Fills a portion of the given big array with the given value.static void
fill
(byte[][] array, byte value) Fills the given big array with the given value.static void
fill
(byte[][] array, long from, long to, byte value) Fills a portion of the given big array with the given value.static void
fill
(char[][] array, char value) Fills the given big array with the given value.static void
fill
(char[][] array, long from, long to, char value) Fills a portion of the given big array with the given value.static void
fill
(double[][] array, double value) Fills the given big array with the given value.static void
fill
(double[][] array, long from, long to, double value) Fills a portion of the given big array with the given value.static void
fill
(float[][] array, float value) Fills the given big array with the given value.static void
fill
(float[][] array, long from, long to, float value) Fills a portion of the given big array with the given value.static void
fill
(int[][] array, int value) Fills the given big array with the given value.static void
fill
(int[][] array, long from, long to, int value) Fills a portion of the given big array with the given value.static void
fill
(long[][] array, long value) Fills the given big array with the given value.static void
fill
(long[][] array, long from, long to, long value) Fills a portion of the given big array with the given value.static void
fill
(short[][] array, long from, long to, short value) Fills a portion of the given big array with the given value.static void
fill
(short[][] array, short value) Fills the given big array with the given value.static <K> void
fill
(K[][] array, long from, long to, K value) Fills a portion of the given big array with the given value.static <K> void
fill
(K[][] array, K value) Fills the given big array with the given value.static boolean[][]
forceCapacity
(boolean[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static byte[][]
forceCapacity
(byte[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static char[][]
forceCapacity
(char[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static double[][]
forceCapacity
(double[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static float[][]
forceCapacity
(float[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static int[][]
forceCapacity
(int[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static long[][]
forceCapacity
(long[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static short[][]
forceCapacity
(short[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static <K> K[][]
forceCapacity
(K[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.static boolean
get
(boolean[][] array, long index) Returns the element of the given big array of specified index.static byte
get
(byte[][] array, long index) Returns the element of the given big array of specified index.static char
get
(char[][] array, long index) Returns the element of the given big array of specified index.static double
get
(double[][] array, long index) Returns the element of the given big array of specified index.static float
get
(float[][] array, long index) Returns the element of the given big array of specified index.static int
get
(int[][] array, long index) Returns the element of the given big array of specified index.static long
get
(long[][] array, long index) Returns the element of the given big array of specified index.static short
get
(short[][] array, long index) Returns the element of the given big array of specified index.static int
get
(AtomicIntegerArray[] array, long index) Returns the element of the given big atomic array of specified index.static long
get
(AtomicLongArray[] array, long index) Returns the element of the given big atomic array of specified index.static <K> K
get
(K[][] array, long index) Returns the element of the given big array of specified index.static int
getAndAdd
(AtomicIntegerArray[] array, long index, int value) Atomically adds a value to an element of the given big atomic array, returning the old value.static long
getAndAdd
(AtomicLongArray[] array, long index, long value) Atomically adds a value to an element of the given big atomic array, returning the old value.static int
getAndDecrement
(AtomicIntegerArray[] array, long index) Atomically decrements an element of the given big atomic array, returning the old value.static long
getAndDecrement
(AtomicLongArray[] array, long index) Atomically decrements an element of the given big atomic array, returning the old value.static int
getAndIncrement
(AtomicIntegerArray[] array, long index) Atomically increments an element of the given big atomic array, returning the old value.static long
getAndIncrement
(AtomicLongArray[] array, long index) Atomically increments an element of the given big atomic array, returning the old value.static int
getAndSet
(AtomicIntegerArray[] array, long index, int value) Atomically sets an element of the given big atomic array to a specified value, returning the old value.static long
getAndSet
(AtomicLongArray[] array, long index, long value) Atomically sets an element of the given big atomic array to a specified value, returning the old value.static boolean[][]
grow
(boolean[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static boolean[][]
grow
(boolean[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static byte[][]
grow
(byte[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static byte[][]
grow
(byte[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static char[][]
grow
(char[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static char[][]
grow
(char[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static double[][]
grow
(double[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static double[][]
grow
(double[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static float[][]
grow
(float[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static float[][]
grow
(float[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static int[][]
grow
(int[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static int[][]
grow
(int[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static long[][]
grow
(long[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static long[][]
grow
(long[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static short[][]
grow
(short[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static short[][]
grow
(short[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static <K> K[][]
grow
(K[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.static <K> K[][]
grow
(K[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.static void
incr
(byte[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(char[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(double[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(float[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(int[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(long[][] array, long index) Increments the element of the given big array of specified index.static void
incr
(short[][] array, long index) Increments the element of the given big array of specified index.static int
incrementAndGet
(AtomicIntegerArray[] array, long index) Atomically increments an element of the given big atomic array, returning the new value.static long
incrementAndGet
(AtomicLongArray[] array, long index) Atomically increments an element of the given big atomic array, returning the new value.static long
index
(int segment, int displacement) Computes the index associated with given segment and displacement.static long
length
(boolean[][] array) Returns the length of the given big array.static long
length
(byte[][] array) Returns the length of the given big array.static long
length
(char[][] array) Returns the length of the given big array.static long
length
(double[][] array) Returns the length of the given big array.static long
length
(float[][] array) Returns the length of the given big array.static long
length
(int[][] array) Returns the length of the given big array.static long
length
(long[][] array) Returns the length of the given big array.static long
length
(short[][] array) Returns the length of the given big array.static long
length
(AtomicIntegerArray[] array) Returns the length of the given big atomic array.static long
length
(AtomicLongArray[] array) Returns the length of the given big atomic array.static <K> long
length
(K[][] array) Returns the length of the given big array.static void
static void
mergeSort
(long from, long to, LongComparator comp, BigSwapper swapper) Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using mergesort.static void
mul
(byte[][] array, long index, byte factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(char[][] array, long index, char factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(double[][] array, long index, double factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(float[][] array, long index, float factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(int[][] array, long index, int factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(long[][] array, long index, long factor) Multiplies by the specified factor the element of the given big array of specified index.static void
mul
(short[][] array, long index, short factor) Multiplies by the specified factor the element of the given big array of specified index.static long
nearestSegmentStart
(long index, long min, long max) Computes the nearest segment starting index of a given index.static void
quickSort
(long from, long to, LongComparator comp, BigSwapper swapper) Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using quicksort.static boolean[][]
reverse
(boolean[][] a) Reverses the order of the elements in the specified big array.static byte[][]
reverse
(byte[][] a) Reverses the order of the elements in the specified big array.static char[][]
reverse
(char[][] a) Reverses the order of the elements in the specified big array.static double[][]
reverse
(double[][] a) Reverses the order of the elements in the specified big array.static float[][]
reverse
(float[][] a) Reverses the order of the elements in the specified big array.static int[][]
reverse
(int[][] a) Reverses the order of the elements in the specified big array.static long[][]
reverse
(long[][] a) Reverses the order of the elements in the specified big array.static short[][]
reverse
(short[][] a) Reverses the order of the elements in the specified big array.static <K> K[][]
reverse
(K[][] a) Reverses the order of the elements in the specified big array.static int
segment
(long index) Computes the segment associated with a given index.static void
set
(boolean[][] array, long index, boolean value) Sets the element of the given big array of specified index.static void
set
(byte[][] array, long index, byte value) Sets the element of the given big array of specified index.static void
set
(char[][] array, long index, char value) Sets the element of the given big array of specified index.static void
set
(double[][] array, long index, double value) Sets the element of the given big array of specified index.static void
set
(float[][] array, long index, float value) Sets the element of the given big array of specified index.static void
set
(int[][] array, long index, int value) Sets the element of the given big array of specified index.static void
set
(long[][] array, long index, long value) Sets the element of the given big array of specified index.static void
set
(short[][] array, long index, short value) Sets the element of the given big array of specified index.static void
set
(AtomicIntegerArray[] array, long index, int value) Sets an element of the given big atomic array to a specified valuestatic void
set
(AtomicLongArray[] array, long index, long value) Sets an element of the given big atomic array to a specified valuestatic <K> void
set
(K[][] array, long index, K value) Sets the element of the given big array of specified index.static boolean[][]
setLength
(boolean[][] array, long length) Sets the length of the given big array.static byte[][]
setLength
(byte[][] array, long length) Sets the length of the given big array.static char[][]
setLength
(char[][] array, long length) Sets the length of the given big array.static double[][]
setLength
(double[][] array, long length) Sets the length of the given big array.static float[][]
setLength
(float[][] array, long length) Sets the length of the given big array.static int[][]
setLength
(int[][] array, long length) Sets the length of the given big array.static long[][]
setLength
(long[][] array, long length) Sets the length of the given big array.static short[][]
setLength
(short[][] array, long length) Sets the length of the given big array.static <K> K[][]
setLength
(K[][] array, long length) Sets the length of the given big array.static boolean[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static boolean[][]
Shuffles the specified big array using the specified pseudorandom number generator.static byte[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static byte[][]
Shuffles the specified big array using the specified pseudorandom number generator.static char[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static char[][]
Shuffles the specified big array using the specified pseudorandom number generator.static double[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static double[][]
Shuffles the specified big array using the specified pseudorandom number generator.static float[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static float[][]
Shuffles the specified big array using the specified pseudorandom number generator.static int[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static int[][]
Shuffles the specified big array using the specified pseudorandom number generator.static long[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static long[][]
Shuffles the specified big array using the specified pseudorandom number generator.static short[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static short[][]
Shuffles the specified big array using the specified pseudorandom number generator.static <K> K[][]
Shuffles the specified big array fragment using the specified pseudorandom number generator.static <K> K[][]
Shuffles the specified big array using the specified pseudorandom number generator.static long
start
(int segment) Computes the starting index of a given segment.static void
swap
(boolean[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(byte[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(char[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(double[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(float[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(int[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(long[][] array, long first, long second) Swaps the element of the given big array of specified indices.static void
swap
(short[][] array, long first, long second) Swaps the element of the given big array of specified indices.static <K> void
swap
(K[][] array, long first, long second) Swaps the element of the given big array of specified indices.static String
toString
(boolean[][] a) static String
toString
(byte[][] a) static String
toString
(char[][] a) static String
toString
(double[][] a) static String
toString
(float[][] a) static String
toString
(int[][] a) static String
toString
(long[][] a) static String
toString
(short[][] a) static <K> String
toString
(K[][] a) static boolean[][]
trim
(boolean[][] array, long length) Trims the given big array to the given length.static byte[][]
trim
(byte[][] array, long length) Trims the given big array to the given length.static char[][]
trim
(char[][] array, long length) Trims the given big array to the given length.static double[][]
trim
(double[][] array, long length) Trims the given big array to the given length.static float[][]
trim
(float[][] array, long length) Trims the given big array to the given length.static int[][]
trim
(int[][] array, long length) Trims the given big array to the given length.static long[][]
trim
(long[][] array, long length) Trims the given big array to the given length.static short[][]
trim
(short[][] array, long length) Trims the given big array to the given length.static <K> K[][]
trim
(K[][] array, long length) Trims the given big array to the given length.static boolean[][]
wrap
(boolean[] array) Turns a standard array into a big array.static byte[][]
wrap
(byte[] array) Turns a standard array into a big array.static char[][]
wrap
(char[] array) Turns a standard array into a big array.static double[][]
wrap
(double[] array) Turns a standard array into a big array.static float[][]
wrap
(float[] array) Turns a standard array into a big array.static int[][]
wrap
(int[] array) Turns a standard array into a big array.static long[][]
wrap
(long[] array) Turns a standard array into a big array.static short[][]
wrap
(short[] array) Turns a standard array into a big array.static <K> K[][]
wrap
(K[] array) Turns a standard array into a big array.
-
Field Details
-
SEGMENT_SHIFT
public static final int SEGMENT_SHIFTThe shift used to compute the segment associated with an index (equivalently, the logarithm of the segment size).- See Also:
-
SEGMENT_SIZE
public static final int SEGMENT_SIZEThe current size of a segment (227) is the largest size that makes the physical memory allocation for a single segment strictly smaller than 231 bytes.- See Also:
-
SEGMENT_MASK
public static final int SEGMENT_MASKThe mask used to compute the displacement associated to an index.- See Also:
-
-
Method Details
-
segment
public static int segment(long index) Computes the segment associated with a given index.- Parameters:
index
- an index into a big array.- Returns:
- the associated segment.
-
displacement
public static int displacement(long index) Computes the displacement associated with a given index.- Parameters:
index
- an index into a big array.- Returns:
- the associated displacement (in the associated segment).
-
start
public static long start(int segment) Computes the starting index of a given segment.- Parameters:
segment
- the segment of a big array.- Returns:
- the starting index of the segment.
-
nearestSegmentStart
public static long nearestSegmentStart(long index, long min, long max) Computes the nearest segment starting index of a given index.This will either be
start(segment(index)
orstart(segment(index) + 1)
, whichever is closer, given the bounds can be respected. If neither segment start is within the bounds, then the index is returned unmodified.This method can be useful for operations that seek to align on the outer array's boundaries when possible.
- Parameters:
index
- an index into a big array.min
- the minimum (inclusive) valid index of the big array in questionmax
- the maximum (exclusive) valid index of the big array in question- Returns:
- the closest segment starting index to
index
- Since:
- 8.5.0
- Implementation Specification:
- The current implementation is branch heavy and is thus not suitable for use in inner loops. However, it should be fine for the recursive step, where split points are computed.
-
index
public static long index(int segment, int displacement) Computes the index associated with given segment and displacement.- Parameters:
segment
- the segment of a big array.displacement
- the displacement into the segment.- Returns:
- the associated index: that is,
segment(index(segment, displacement)) == segment
anddisplacement(index(segment, displacement)) == displacement
.
-
ensureFromTo
public static void ensureFromTo(long bigArrayLength, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array of given length.This method may be used whenever a big array range check is needed.
- Parameters:
bigArrayLength
- a big-array length (must be nonnegative).from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater thanbigArrayLength
or negative.- Implementation Notes:
- An
assert
checks whetherbigArrayLength
is nonnegative.
-
ensureOffsetLength
public static void ensureOffsetLength(long bigArrayLength, long offset, long length) Ensures that a range given by an offset and a length fits a big array of given length.This method may be used whenever a big array range check is needed.
- Parameters:
bigArrayLength
- a big-array length (must be nonnegative).offset
- a start index for the fragmentlength
- a length (the number of elements in the fragment).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater thanbigArrayLength
.- Implementation Notes:
- An
assert
checks whetherbigArrayLength
is nonnegative.
-
ensureLength
public static void ensureLength(long bigArrayLength) Ensures that a big-array length is legal.- Parameters:
bigArrayLength
- a big-array length.- Throws:
IllegalArgumentException
- iflength
is negative, or larger than or equal toSEGMENT_SIZE
*Integer.MAX_VALUE
.
-
mergeSort
Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using mergesort.This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. The sorting algorithm is an in-place mergesort that is significantly slower than a standard mergesort, as its running time is O(n (log n)2), but it does not allocate additional memory; as a result, it can be used as a generic sorting algorithm.
- Parameters:
from
- the index of the first element (inclusive) to be sorted.to
- the index of the last element (exclusive) to be sorted.comp
- the comparator to determine the order of the generic data (arguments are positions).swapper
- an object that knows how to swap the elements at any two positions.
-
quickSort
Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using quicksort.The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.
- Parameters:
from
- the index of the first element (inclusive) to be sorted.to
- the index of the last element (exclusive) to be sorted.comp
- the comparator to determine the order of the generic data.swapper
- an object that knows how to swap the elements at any two positions.
-
get
public static byte get(byte[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(byte[][] array, long index, byte value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(byte[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static byte[][] reverse(byte[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(byte[][] array, long index, byte incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(byte[][] array, long index, byte factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(byte[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(byte[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(byte[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(byte[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(byte[][] srcArray, long srcPos, byte[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(byte[][] srcArray, long srcPos, byte[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(byte[] srcArray, int srcPos, byte[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static byte[][] wrap(byte[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static byte[][] ensureCapacity(byte[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static byte[][] forceCapacity(byte[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static byte[][] ensureCapacity(byte[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static byte[][] grow(byte[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static byte[][] grow(byte[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static byte[][] trim(byte[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static byte[][] setLength(byte[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static byte[][] copy(byte[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static byte[][] copy(byte[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(byte[][] array, byte value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(byte[][] array, long from, long to, byte value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(byte[][] a1, byte[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(byte[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(byte[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(byte[][] a, byte[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static int get(int[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(int[][] array, long index, int value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
length
Returns the length of the given big atomic array.- Parameters:
array
- a big atomic array.- Returns:
- the length of the given big atomic array.
-
get
Returns the element of the given big atomic array of specified index.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the element of the big atomic array at the specified position.
-
set
Sets an element of the given big atomic array to a specified value- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a new value for the element of the big atomic array at the specified position.
-
getAndSet
Atomically sets an element of the given big atomic array to a specified value, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a new value for the element of the big atomic array at the specified position.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
getAndAdd
Atomically adds a value to an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a value to add to the element of the big atomic array at the specified position.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
addAndGet
Atomically adds a value to an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a value to add to the element of the big atomic array at the specified position.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
getAndIncrement
Atomically increments an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
incrementAndGet
Atomically increments an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
getAndDecrement
Atomically decrements an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
decrementAndGet
Atomically decrements an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
compareAndSet
public static boolean compareAndSet(AtomicIntegerArray[] array, long index, int expected, int value) Atomically sets an element of the given big atomic array of specified index to specified value, given the current value is equal to a given expected value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.expected
- an expected value for the element of the big atomic array at the specified position.value
- a new value for the element of the big atomic array at the specified position.- Returns:
- the element of the big atomic array at the specified position.
-
swap
public static void swap(int[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static int[][] reverse(int[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(int[][] array, long index, int incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(int[][] array, long index, int factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(int[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(int[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(int[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(int[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(int[][] srcArray, long srcPos, int[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(int[][] srcArray, long srcPos, int[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(int[] srcArray, int srcPos, int[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static int[][] wrap(int[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static int[][] ensureCapacity(int[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static int[][] forceCapacity(int[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static int[][] ensureCapacity(int[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static int[][] grow(int[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static int[][] grow(int[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static int[][] trim(int[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static int[][] setLength(int[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static int[][] copy(int[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static int[][] copy(int[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(int[][] array, int value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(int[][] array, long from, long to, int value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(int[][] a1, int[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(int[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(int[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(int[][] a, int[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static long get(long[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(long[][] array, long index, long value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
length
Returns the length of the given big atomic array.- Parameters:
array
- a big atomic array.- Returns:
- the length of the given big atomic array.
-
get
Returns the element of the given big atomic array of specified index.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the element of the big atomic array at the specified position.
-
set
Sets an element of the given big atomic array to a specified value- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a new value for the element of the big atomic array at the specified position.
-
getAndSet
Atomically sets an element of the given big atomic array to a specified value, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a new value for the element of the big atomic array at the specified position.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
getAndAdd
Atomically adds a value to an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a value to add to the element of the big atomic array at the specified position.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
addAndGet
Atomically adds a value to an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.value
- a value to add to the element of the big atomic array at the specified position.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
getAndIncrement
Atomically increments an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
incrementAndGet
Atomically increments an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
getAndDecrement
Atomically decrements an element of the given big atomic array, returning the old value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the old value of the element of the big atomic array at the specified position.
-
decrementAndGet
Atomically decrements an element of the given big atomic array, returning the new value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.- Returns:
- the new value of the element of the big atomic array at the specified position.
-
compareAndSet
Atomically sets an element of the given big atomic array of specified index to specified value, given the current value is equal to a given expected value.- Parameters:
array
- a big atomic array.index
- a position in the big atomic array.expected
- an expected value for the element of the big atomic array at the specified position.value
- a new value for the element of the big atomic array at the specified position.- Returns:
- the element of the big atomic array at the specified position.
-
swap
public static void swap(long[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static long[][] reverse(long[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(long[][] array, long index, long incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(long[][] array, long index, long factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(long[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(long[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(long[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(long[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(long[][] srcArray, long srcPos, long[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(long[][] srcArray, long srcPos, long[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(long[] srcArray, int srcPos, long[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static long[][] wrap(long[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static long[][] ensureCapacity(long[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static long[][] forceCapacity(long[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static long[][] ensureCapacity(long[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static long[][] grow(long[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static long[][] grow(long[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static long[][] trim(long[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static long[][] setLength(long[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static long[][] copy(long[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static long[][] copy(long[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(long[][] array, long value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(long[][] array, long from, long to, long value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(long[][] a1, long[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(long[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(long[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(long[][] a, long[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static double get(double[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(double[][] array, long index, double value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(double[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static double[][] reverse(double[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(double[][] array, long index, double incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(double[][] array, long index, double factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(double[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(double[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(double[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(double[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(double[][] srcArray, long srcPos, double[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(double[][] srcArray, long srcPos, double[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(double[] srcArray, int srcPos, double[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static double[][] wrap(double[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static double[][] ensureCapacity(double[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static double[][] forceCapacity(double[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static double[][] ensureCapacity(double[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static double[][] grow(double[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static double[][] grow(double[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static double[][] trim(double[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static double[][] setLength(double[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static double[][] copy(double[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static double[][] copy(double[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(double[][] array, double value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(double[][] array, long from, long to, double value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(double[][] a1, double[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(double[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(double[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(double[][] a, double[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static boolean get(boolean[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(boolean[][] array, long index, boolean value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(boolean[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static boolean[][] reverse(boolean[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
assertBigArray
public static void assertBigArray(boolean[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(boolean[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(boolean[][] srcArray, long srcPos, boolean[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(boolean[][] srcArray, long srcPos, boolean[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(boolean[] srcArray, int srcPos, boolean[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static boolean[][] wrap(boolean[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static boolean[][] ensureCapacity(boolean[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static boolean[][] forceCapacity(boolean[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static boolean[][] ensureCapacity(boolean[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static boolean[][] grow(boolean[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static boolean[][] grow(boolean[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static boolean[][] trim(boolean[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static boolean[][] setLength(boolean[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static boolean[][] copy(boolean[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static boolean[][] copy(boolean[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(boolean[][] array, boolean value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(boolean[][] array, long from, long to, boolean value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(boolean[][] a1, boolean[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(boolean[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(boolean[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(boolean[][] a, boolean[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static short get(short[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(short[][] array, long index, short value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(short[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static short[][] reverse(short[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(short[][] array, long index, short incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(short[][] array, long index, short factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(short[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(short[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(short[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(short[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(short[][] srcArray, long srcPos, short[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(short[][] srcArray, long srcPos, short[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(short[] srcArray, int srcPos, short[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static short[][] wrap(short[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static short[][] ensureCapacity(short[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static short[][] forceCapacity(short[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static short[][] ensureCapacity(short[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static short[][] grow(short[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static short[][] grow(short[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static short[][] trim(short[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static short[][] setLength(short[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static short[][] copy(short[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static short[][] copy(short[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(short[][] array, short value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(short[][] array, long from, long to, short value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(short[][] a1, short[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(short[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(short[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(short[][] a, short[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static char get(char[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(char[][] array, long index, char value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(char[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static char[][] reverse(char[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(char[][] array, long index, char incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(char[][] array, long index, char factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(char[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(char[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(char[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(char[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(char[][] srcArray, long srcPos, char[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(char[][] srcArray, long srcPos, char[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(char[] srcArray, int srcPos, char[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static char[][] wrap(char[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static char[][] ensureCapacity(char[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static char[][] forceCapacity(char[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static char[][] ensureCapacity(char[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static char[][] grow(char[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static char[][] grow(char[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static char[][] trim(char[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static char[][] setLength(char[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static char[][] copy(char[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static char[][] copy(char[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(char[][] array, char value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(char[][] array, long from, long to, char value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(char[][] a1, char[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(char[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(char[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(char[][] a, char[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static float get(float[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static void set(float[][] array, long index, float value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static void swap(float[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static float[][] reverse(float[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
add
public static void add(float[][] array, long index, float incr) Adds the specified increment the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.incr
- the increment
-
mul
public static void mul(float[][] array, long index, float factor) Multiplies by the specified factor the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.factor
- the factor
-
incr
public static void incr(float[][] array, long index) Increments the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
decr
public static void decr(float[][] array, long index) Decrements the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.
-
assertBigArray
public static void assertBigArray(float[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static long length(float[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static void copy(float[][] srcArray, long srcPos, float[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static void copyFromBig(float[][] srcArray, long srcPos, float[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static void copyToBig(float[] srcArray, int srcPos, float[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static float[][] wrap(float[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static float[][] ensureCapacity(float[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static float[][] forceCapacity(float[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static float[][] ensureCapacity(float[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static float[][] grow(float[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static float[][] grow(float[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static float[][] trim(float[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static float[][] setLength(float[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static float[][] copy(float[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static float[][] copy(float[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static void fill(float[][] array, float value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static void fill(float[][] array, long from, long to, float value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static boolean equals(float[][] a1, float[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static void ensureFromTo(float[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static void ensureOffsetLength(float[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static void ensureSameLength(float[][] a, float[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
get
public static <K> K get(K[][] array, long index) Returns the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.- Returns:
- the element of the big array at the specified position.
-
set
public static <K> void set(K[][] array, long index, K value) Sets the element of the given big array of specified index.- Parameters:
array
- a big array.index
- a position in the big array.value
- the new value for the array element at the specified position.
-
swap
public static <K> void swap(K[][] array, long first, long second) Swaps the element of the given big array of specified indices.- Parameters:
array
- a big array.first
- a position in the big array.second
- a position in the big array.
-
reverse
public static <K> K[][] reverse(K[][] a) Reverses the order of the elements in the specified big array.- Parameters:
a
- the big array to be reversed.- Returns:
a
.
-
assertBigArray
public static <K> void assertBigArray(K[][] array) Asserts that the provided big array is correct.- Parameters:
array
- a big array.- Throws:
IllegalStateException
- if the last segment is empty or longer thanSEGMENT_SIZE
, or any other segment has length different fromSEGMENT_SIZE
.
-
length
public static <K> long length(K[][] array) Returns the length of the given big array.- Parameters:
array
- a big array.- Returns:
- the length of the given big array.
-
copy
public static <K> void copy(K[][] srcArray, long srcPos, K[][] destArray, long destPos, long length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyFromBig
public static <K> void copyFromBig(K[][] srcArray, long srcPos, K[] destArray, int destPos, int length) Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.- Parameters:
srcArray
- the source big array.srcPos
- the starting position in the source big array.destArray
- the destination array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
copyToBig
public static <K> void copyToBig(K[] srcArray, int srcPos, K[][] destArray, long destPos, long length) Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.- Parameters:
srcArray
- the source array.srcPos
- the starting position in the source array.destArray
- the destination big array.destPos
- the starting position in the destination data.length
- the number of elements to be copied.
-
wrap
public static <K> K[][] wrap(K[] array) Turns a standard array into a big array.Note that the returned big array might contain as a segment the original array.
- Parameters:
array
- an array.- Returns:
- a new big array with the same length and content of
array
.
-
ensureCapacity
public static <K> K[][] ensureCapacity(K[][] array, long length) Ensures that a big array can contain the given number of entries.If you cannot foresee whether this big array will need again to be enlarged, you should probably use
grow()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it containslength
entries or more; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
forceCapacity
public static <K> K[][] forceCapacity(K[][] array, long length, long preserve) Forces a big array to contain the given number of entries, preserving just a part of the big array.This method returns a new big array of the given length whose element are of the same class as of those of
array
.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
- a big array with
length
entries whose firstpreserve
entries are the same as those ofarray
.
-
ensureCapacity
public static <K> K[][] ensureCapacity(K[][] array, long length, long preserve) Ensures that a big array can contain the given number of entries, preserving just a part of the big array.This method returns a new big array of the given length whose element are of the same class as of those of
array
.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries or more; otherwise, a big array withlength
entries whose firstpreserve
entries are the same as those ofarray
.
-
grow
public static <K> K[][] grow(K[][] array, long length) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstlength(array)
entries are the same as those ofarray
.
-
grow
public static <K> K[][] grow(K[][] array, long length, long preserve) Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.If you want complete control on the big array growth, you should probably use
ensureCapacity()
instead.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new minimum length for this big array.preserve
- the number of elements of the big array that must be preserved in case a new allocation is necessary.- Returns:
array
, if it can containlength
entries; otherwise, a big array with max(length
,length(array)
/φ) entries whose firstpreserve
entries are the same as those ofarray
.
-
trim
public static <K> K[][] trim(K[][] array, long length) Trims the given big array to the given length.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new maximum length for the big array.- Returns:
array
, if it containslength
entries or less; otherwise, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
.
-
setLength
public static <K> K[][] setLength(K[][] array, long length) Sets the length of the given big array.Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.
- Parameters:
array
- a big array.length
- the new length for the big array.- Returns:
array
, if it contains exactlylength
entries; otherwise, if it contains more thanlength
entries, a big array withlength
entries whose entries are the same as the firstlength
entries ofarray
; otherwise, a big array withlength
entries whose firstlength(array)
entries are the same as those ofarray
.
-
copy
public static <K> K[][] copy(K[][] array, long offset, long length) Returns a copy of a portion of a big array.- Parameters:
array
- a big array.offset
- the first element to copy.length
- the number of elements to copy.- Returns:
- a new big array containing
length
elements ofarray
starting atoffset
.
-
copy
public static <K> K[][] copy(K[][] array) Returns a copy of a big array.- Parameters:
array
- a big array.- Returns:
- a copy of
array
.
-
fill
public static <K> void fill(K[][] array, K value) Fills the given big array with the given value.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
array
- a big array.value
- the new value for all elements of the big array.
-
fill
public static <K> void fill(K[][] array, long from, long to, K value) Fills a portion of the given big array with the given value.If possible (i.e.,
from
is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method inArrays
.- Parameters:
array
- a big array.from
- the starting index of the portion to fill.to
- the end index of the portion to fill.value
- the new value for all elements of the specified portion of the big array.
-
equals
public static <K> boolean equals(K[][] a1, K[][] a2) Returns true if the two big arrays are elementwise equal.This method uses a backward loop. It is significantly faster than the corresponding method in
Arrays
.- Parameters:
a1
- a big array.a2
- another big array.- Returns:
- true if the two big arrays are of the same length, and their elements are equal.
-
toString
-
ensureFromTo
public static <K> void ensureFromTo(K[][] a, long from, long to) Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.from
- a start index (inclusive).to
- an end index (inclusive).- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.ArrayIndexOutOfBoundsException
- iffrom
orto
are greater than the big array length or negative.
-
ensureOffsetLength
public static <K> void ensureOffsetLength(K[][] a, long offset, long length) Ensures that a range given by an offset and a length fits a big array.This method may be used whenever a big array range check is needed.
- Parameters:
a
- a big array.offset
- a start index.length
- a length (the number of elements in the range).- Throws:
IllegalArgumentException
- iflength
is negative.ArrayIndexOutOfBoundsException
- ifoffset
is negative oroffset
+length
is greater than the big array length.
-
ensureSameLength
public static <K> void ensureSameLength(K[][] a, K[][] b) Ensures that two big arrays are of the same length.- Parameters:
a
- a big array.b
- another big array.- Throws:
IllegalArgumentException
- if the two argument arrays are not of the same length.
-
shuffle
Shuffles the specified big array fragment using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.from
- the index of the first element (inclusive) to be shuffled.to
- the index of the last element (exclusive) to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
shuffle
Shuffles the specified big array using the specified pseudorandom number generator.- Parameters:
a
- the big array to be shuffled.random
- a pseudorandom number generator.- Returns:
a
.
-
main
-