Class BigArrays
public class BigArrays extends Object
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 defined in the type-specific versions (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., IntBigArrays.wrap(int[])) around a
literal standard array. Alternatively, for very small arrays you can just
declare a literal array-of-array (e.g., new int[][] { { 1, 2 } }).
Be warned, however, that this can lead to creating illegal big arrays if
for some reason (e.g., stress testing) SEGMENT_SIZE is set to a
value smaller than the inner array length.
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:
Arrays
-
Field Summary
Fields Modifier and Type Field Description static intSEGMENT_MASKThe mask used to compute the displacement associated to an index.static intSEGMENT_SHIFTThe shift used to compute the segment associated with an index (equivalently, the logarithm of the segment size).static intSEGMENT_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. -
Method Summary
Modifier and Type Method Description static voidadd(byte[][] array, long index, byte incr)Adds the specified increment the element of the given big array of specified index.static voidadd(char[][] array, long index, char incr)Adds the specified increment the element of the given big array of specified index.static voidadd(double[][] array, long index, double incr)Adds the specified increment the element of the given big array of specified index.static voidadd(float[][] array, long index, float incr)Adds the specified increment the element of the given big array of specified index.static voidadd(int[][] array, long index, int incr)Adds the specified increment the element of the given big array of specified index.static voidadd(long[][] array, long index, long incr)Adds the specified increment the element of the given big array of specified index.static voidadd(short[][] array, long index, short incr)Adds the specified increment the element of the given big array of specified index.static boolean[][]copy(boolean[][] array)Returns a copy of a big array.static voidcopy(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 voidcopy(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 voidcopy(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 voidcopy(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 voidcopy(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 voidcopy(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 voidcopy(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 voidcopy(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> voidcopy(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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 voidcopyFromBig(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> voidcopyFromBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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 voidcopyToBig(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> voidcopyToBig(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 voiddecr(byte[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(char[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(double[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(float[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(int[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(long[][] array, long index)Decrements the element of the given big array of specified index.static voiddecr(short[][] array, long index)Decrements the element of the given big array of specified index.static intdisplacement(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 voidensureFromTo(boolean[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(byte[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(char[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(double[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(float[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(int[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(long[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureFromTo(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 voidensureFromTo(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> voidensureFromTo(K[][] a, long from, long to)Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.static voidensureLength(long bigArrayLength)Ensures that a big-array length is legal.static voidensureOffsetLength(boolean[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(byte[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(char[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(double[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(float[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(int[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(long[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureOffsetLength(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 voidensureOffsetLength(short[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static <K> voidensureOffsetLength(K[][] a, long offset, long length)Ensures that a range given by an offset and a length fits a big array.static voidensureSameLength(boolean[][] a, boolean[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(byte[][] a, byte[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(char[][] a, char[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(double[][] a, double[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(float[][] a, float[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(int[][] a, int[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(long[][] a, long[][] b)Ensures that two big arrays are of the same length.static voidensureSameLength(short[][] a, short[][] b)Ensures that two big arrays are of the same length.static <K> voidensureSameLength(K[][] a, K[][] b)Ensures that two big arrays are of the same length.static booleanequals(boolean[][] a1, boolean[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(byte[][] a1, byte[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(char[][] a1, char[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(double[][] a1, double[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(float[][] a1, float[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(int[][] a1, int[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(long[][] a1, long[][] a2)Returns true if the two big arrays are elementwise equal.static booleanequals(short[][] a1, short[][] a2)Returns true if the two big arrays are elementwise equal.static <K> booleanequals(K[][] a1, K[][] a2)Returns true if the two big arrays are elementwise equal.static voidfill(boolean[][] array, boolean value)Fills the given big array with the given value.static voidfill(boolean[][] array, long from, long to, boolean value)Fills a portion of the given big array with the given value.static voidfill(byte[][] array, byte value)Fills the given big array with the given value.static voidfill(byte[][] array, long from, long to, byte value)Fills a portion of the given big array with the given value.static voidfill(char[][] array, char value)Fills the given big array with the given value.static voidfill(char[][] array, long from, long to, char value)Fills a portion of the given big array with the given value.static voidfill(double[][] array, double value)Fills the given big array with the given value.static voidfill(double[][] array, long from, long to, double value)Fills a portion of the given big array with the given value.static voidfill(float[][] array, float value)Fills the given big array with the given value.static voidfill(float[][] array, long from, long to, float value)Fills a portion of the given big array with the given value.static voidfill(int[][] array, int value)Fills the given big array with the given value.static voidfill(int[][] array, long from, long to, int value)Fills a portion of the given big array with the given value.static voidfill(long[][] array, long value)Fills the given big array with the given value.static voidfill(long[][] array, long from, long to, long value)Fills a portion of the given big array with the given value.static voidfill(short[][] array, long from, long to, short value)Fills a portion of the given big array with the given value.static voidfill(short[][] array, short value)Fills the given big array with the given value.static <K> voidfill(K[][] array, long from, long to, K value)Fills a portion of the given big array with the given value.static <K> voidfill(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 booleanget(boolean[][] array, long index)Returns the element of the given big array of specified index.static byteget(byte[][] array, long index)Returns the element of the given big array of specified index.static charget(char[][] array, long index)Returns the element of the given big array of specified index.static doubleget(double[][] array, long index)Returns the element of the given big array of specified index.static floatget(float[][] array, long index)Returns the element of the given big array of specified index.static intget(int[][] array, long index)Returns the element of the given big array of specified index.static longget(long[][] array, long index)Returns the element of the given big array of specified index.static shortget(short[][] array, long index)Returns the element of the given big array of specified index.static <K> Kget(K[][] array, long index)Returns the element of the given big array of specified index.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 voidincr(byte[][] array, long index)Increments the element of the given big array of specified index.static voidincr(char[][] array, long index)Increments the element of the given big array of specified index.static voidincr(double[][] array, long index)Increments the element of the given big array of specified index.static voidincr(float[][] array, long index)Increments the element of the given big array of specified index.static voidincr(int[][] array, long index)Increments the element of the given big array of specified index.static voidincr(long[][] array, long index)Increments the element of the given big array of specified index.static voidincr(short[][] array, long index)Increments the element of the given big array of specified index.static longindex(int segment, int displacement)Computes the index associated with given segment and displacement.static longlength(boolean[][] array)Returns the length of the given big array.static longlength(byte[][] array)Returns the length of the given big array.static longlength(char[][] array)Returns the length of the given big array.static longlength(double[][] array)Returns the length of the given big array.static longlength(float[][] array)Returns the length of the given big array.static longlength(int[][] array)Returns the length of the given big array.static longlength(long[][] array)Returns the length of the given big array.static longlength(short[][] array)Returns the length of the given big array.static <K> longlength(K[][] array)Returns the length of the given big array.static voidmain(String[] arg)static voidmergeSort(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 voidmul(byte[][] array, long index, byte factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(char[][] array, long index, char factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(double[][] array, long index, double factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(float[][] array, long index, float factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(int[][] array, long index, int factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(long[][] array, long index, long factor)Multiplies by the specified factor the element of the given big array of specified index.static voidmul(short[][] array, long index, short factor)Multiplies by the specified factor the element of the given big array of specified index.static voidquickSort(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 intsegment(long index)Computes the segment associated with a given index.static voidset(boolean[][] array, long index, boolean value)Sets the element of the given big array of specified index.static voidset(byte[][] array, long index, byte value)Sets the element of the given big array of specified index.static voidset(char[][] array, long index, char value)Sets the element of the given big array of specified index.static voidset(double[][] array, long index, double value)Sets the element of the given big array of specified index.static voidset(float[][] array, long index, float value)Sets the element of the given big array of specified index.static voidset(int[][] array, long index, int value)Sets the element of the given big array of specified index.static voidset(long[][] array, long index, long value)Sets the element of the given big array of specified index.static voidset(short[][] array, long index, short value)Sets the element of the given big array of specified index.static <K> voidset(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[][]shuffle(boolean[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static boolean[][]shuffle(boolean[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static byte[][]shuffle(byte[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static byte[][]shuffle(byte[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static char[][]shuffle(char[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static char[][]shuffle(char[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static double[][]shuffle(double[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static double[][]shuffle(double[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static float[][]shuffle(float[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static float[][]shuffle(float[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static int[][]shuffle(int[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static int[][]shuffle(int[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static long[][]shuffle(long[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static long[][]shuffle(long[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static short[][]shuffle(short[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static short[][]shuffle(short[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static <K> K[][]shuffle(K[][] a, long from, long to, Random random)Shuffles the specified big array fragment using the specified pseudorandom number generator.static <K> K[][]shuffle(K[][] a, Random random)Shuffles the specified big array using the specified pseudorandom number generator.static longstart(int segment)Computes the starting index of a given segment.static voidswap(boolean[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(byte[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(char[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(double[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(float[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(int[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(long[][] array, long first, long second)Swaps the element of the given big array of specified indices.static voidswap(short[][] array, long first, long second)Swaps the element of the given big array of specified indices.static <K> voidswap(K[][] array, long first, long second)Swaps the element of the given big array of specified indices.static StringtoString(boolean[][] a)static StringtoString(byte[][] a)static StringtoString(char[][] a)static StringtoString(double[][] a)static StringtoString(float[][] a)static StringtoString(int[][] a)static StringtoString(long[][] a)static StringtoString(short[][] a)static <K> StringtoString(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:
- Constant Field Values
-
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:
- Constant Field Values
-
SEGMENT_MASK
public static final int SEGMENT_MASKThe mask used to compute the displacement associated to an index.- See Also:
- Constant Field Values
-
-
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.
-
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)) == segmentanddisplacement(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.from- a start index (inclusive).to- an end index (inclusive).- Throws:
IllegalArgumentException- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare greater thanbigArrayLengthor negative.
-
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.offset- a start index for the fragmentlength- a length (the number of elements in the fragment).- Throws:
IllegalArgumentException- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis greater thanbigArrayLength.
-
ensureLength
public static void ensureLength(long bigArrayLength)Ensures that a big-array length is legal.- Parameters:
bigArrayLength- a big-array length.- Throws:
IllegalArgumentException- iflengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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.
-
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 containslengthentries or more; otherwise, a big array withlengthentries 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
lengthentries whose firstpreserveentries 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 containlengthentries or more; otherwise, a big array withlengthentries whose firstpreserveentries 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 containlengthentries; 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 containlengthentries; otherwise, a big array with max(length,length(array)/φ) entries whose firstpreserveentries 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 containslengthentries or less; otherwise, a big array withlengthentries whose entries are the same as the firstlengthentries 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 exactlylengthentries; otherwise, if it contains more thanlengthentries, a big array withlengthentries whose entries are the same as the firstlengthentries ofarray; otherwise, a big array withlengthentries 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
lengthelements ofarraystarting 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.,
fromis 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- iffromis greater thanto.ArrayIndexOutOfBoundsException- iffromortoare 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- iflengthis negative.ArrayIndexOutOfBoundsException- ifoffsetis negative oroffset+lengthis 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
-