Class BigArrays


  • public class BigArrays
    extends Object
    A class providing static methods and objects that do useful things with big arrays.

    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 int SEGMENT_MASK
      The mask used to compute the displacement associated to an index.
      static int SEGMENT_SHIFT
      The shift used to compute the segment associated with an index (equivalently, the logarithm of the segment size).
      static int SEGMENT_SIZE
      The current size of a segment (227) is the largest size that makes the physical memory allocation for a single segment strictly smaller than 231 bytes.
    • Method Summary

      Modifier and Type Method Description
      static void add​(byte[][] array, long index, byte incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(char[][] array, long index, char incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(double[][] array, long index, double incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(float[][] array, long index, float incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(int[][] array, long index, int incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(long[][] array, long index, long incr)
      Adds the specified increment the element of the given big array of specified index.
      static void add​(short[][] array, long index, short incr)
      Adds the specified increment the element of the given big array of specified index.
      static boolean[][] copy​(boolean[][] array)
      Returns a copy of a big array.
      static void copy​(boolean[][] srcArray, long srcPos, boolean[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static boolean[][] copy​(boolean[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static byte[][] copy​(byte[][] array)
      Returns a copy of a big array.
      static void copy​(byte[][] srcArray, long srcPos, byte[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static byte[][] copy​(byte[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static char[][] copy​(char[][] array)
      Returns a copy of a big array.
      static void copy​(char[][] srcArray, long srcPos, char[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static char[][] copy​(char[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static double[][] copy​(double[][] array)
      Returns a copy of a big array.
      static void copy​(double[][] srcArray, long srcPos, double[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static double[][] copy​(double[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static float[][] copy​(float[][] array)
      Returns a copy of a big array.
      static void copy​(float[][] srcArray, long srcPos, float[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static float[][] copy​(float[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static int[][] copy​(int[][] array)
      Returns a copy of a big array.
      static void copy​(int[][] srcArray, long srcPos, int[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static int[][] copy​(int[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static long[][] copy​(long[][] array)
      Returns a copy of a big array.
      static long[][] copy​(long[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static void copy​(long[][] srcArray, long srcPos, long[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static short[][] copy​(short[][] array)
      Returns a copy of a big array.
      static short[][] copy​(short[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static void copy​(short[][] srcArray, long srcPos, short[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static <K> K[][] copy​(K[][] array)
      Returns a copy of a big array.
      static <K> K[][] copy​(K[][] array, long offset, long length)
      Returns a copy of a portion of a big array.
      static <K> void copy​(K[][] srcArray, long srcPos, K[][] destArray, long destPos, long length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array.
      static void copyFromBig​(boolean[][] srcArray, long srcPos, boolean[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(byte[][] srcArray, long srcPos, byte[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(char[][] srcArray, long srcPos, char[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(double[][] srcArray, long srcPos, double[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(float[][] srcArray, long srcPos, float[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(int[][] srcArray, long srcPos, int[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(long[][] srcArray, long srcPos, long[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyFromBig​(short[][] srcArray, long srcPos, short[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static <K> void copyFromBig​(K[][] srcArray, long srcPos, K[] destArray, int destPos, int length)
      Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
      static void copyToBig​(boolean[] srcArray, int srcPos, boolean[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(byte[] srcArray, int srcPos, byte[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(char[] srcArray, int srcPos, char[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(double[] srcArray, int srcPos, double[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(float[] srcArray, int srcPos, float[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(int[] srcArray, int srcPos, int[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(long[] srcArray, int srcPos, long[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void copyToBig​(short[] srcArray, int srcPos, short[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static <K> void copyToBig​(K[] srcArray, int srcPos, K[][] destArray, long destPos, long length)
      Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
      static void decr​(byte[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(char[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(double[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(float[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(int[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(long[][] array, long index)
      Decrements the element of the given big array of specified index.
      static void decr​(short[][] array, long index)
      Decrements the element of the given big array of specified index.
      static int displacement​(long index)
      Computes the displacement associated with a given index.
      static boolean[][] ensureCapacity​(boolean[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static boolean[][] ensureCapacity​(boolean[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static byte[][] ensureCapacity​(byte[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static byte[][] ensureCapacity​(byte[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static char[][] ensureCapacity​(char[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static char[][] ensureCapacity​(char[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static double[][] ensureCapacity​(double[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static double[][] ensureCapacity​(double[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static float[][] ensureCapacity​(float[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static float[][] ensureCapacity​(float[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static int[][] ensureCapacity​(int[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static int[][] ensureCapacity​(int[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static long[][] ensureCapacity​(long[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static long[][] ensureCapacity​(long[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static short[][] ensureCapacity​(short[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static short[][] ensureCapacity​(short[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static <K> K[][] ensureCapacity​(K[][] array, long length)
      Ensures that a big array can contain the given number of entries.
      static <K> K[][] ensureCapacity​(K[][] array, long length, long preserve)
      Ensures that a big array can contain the given number of entries, preserving just a part of the big array.
      static void ensureFromTo​(boolean[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(byte[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(char[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(double[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(float[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(int[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(long[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureFromTo​(long bigArrayLength, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array of given length.
      static void ensureFromTo​(short[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static <K> void ensureFromTo​(K[][] a, long from, long to)
      Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.
      static void ensureLength​(long bigArrayLength)
      Ensures that a big-array length is legal.
      static void ensureOffsetLength​(boolean[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(byte[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(char[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(double[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(float[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(int[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(long[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureOffsetLength​(long bigArrayLength, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array of given length.
      static void ensureOffsetLength​(short[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static <K> void ensureOffsetLength​(K[][] a, long offset, long length)
      Ensures that a range given by an offset and a length fits a big array.
      static void ensureSameLength​(boolean[][] a, boolean[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(byte[][] a, byte[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(char[][] a, char[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(double[][] a, double[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(float[][] a, float[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(int[][] a, int[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(long[][] a, long[][] b)
      Ensures that two big arrays are of the same length.
      static void ensureSameLength​(short[][] a, short[][] b)
      Ensures that two big arrays are of the same length.
      static <K> void ensureSameLength​(K[][] a, K[][] b)
      Ensures that two big arrays are of the same length.
      static boolean equals​(boolean[][] a1, boolean[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(byte[][] a1, byte[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(char[][] a1, char[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(double[][] a1, double[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(float[][] a1, float[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(int[][] a1, int[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(long[][] a1, long[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static boolean equals​(short[][] a1, short[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static <K> boolean equals​(K[][] a1, K[][] a2)
      Returns true if the two big arrays are elementwise equal.
      static void fill​(boolean[][] array, boolean value)
      Fills the given big array with the given value.
      static void fill​(boolean[][] array, long from, long to, boolean value)
      Fills a portion of the given big array with the given value.
      static void fill​(byte[][] array, byte value)
      Fills the given big array with the given value.
      static void fill​(byte[][] array, long from, long to, byte value)
      Fills a portion of the given big array with the given value.
      static void fill​(char[][] array, char value)
      Fills the given big array with the given value.
      static void fill​(char[][] array, long from, long to, char value)
      Fills a portion of the given big array with the given value.
      static void fill​(double[][] array, double value)
      Fills the given big array with the given value.
      static void fill​(double[][] array, long from, long to, double value)
      Fills a portion of the given big array with the given value.
      static void fill​(float[][] array, float value)
      Fills the given big array with the given value.
      static void fill​(float[][] array, long from, long to, float value)
      Fills a portion of the given big array with the given value.
      static void fill​(int[][] array, int value)
      Fills the given big array with the given value.
      static void fill​(int[][] array, long from, long to, int value)
      Fills a portion of the given big array with the given value.
      static void fill​(long[][] array, long value)
      Fills the given big array with the given value.
      static void fill​(long[][] array, long from, long to, long value)
      Fills a portion of the given big array with the given value.
      static void fill​(short[][] array, long from, long to, short value)
      Fills a portion of the given big array with the given value.
      static void fill​(short[][] array, short value)
      Fills the given big array with the given value.
      static <K> void fill​(K[][] array, long from, long to, K value)
      Fills a portion of the given big array with the given value.
      static <K> void fill​(K[][] array, K value)
      Fills the given big array with the given value.
      static boolean[][] forceCapacity​(boolean[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static byte[][] forceCapacity​(byte[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static char[][] forceCapacity​(char[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static double[][] forceCapacity​(double[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static float[][] forceCapacity​(float[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static int[][] forceCapacity​(int[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static long[][] forceCapacity​(long[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static short[][] forceCapacity​(short[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static <K> K[][] forceCapacity​(K[][] array, long length, long preserve)
      Forces a big array to contain the given number of entries, preserving just a part of the big array.
      static boolean get​(boolean[][] array, long index)
      Returns the element of the given big array of specified index.
      static byte get​(byte[][] array, long index)
      Returns the element of the given big array of specified index.
      static char get​(char[][] array, long index)
      Returns the element of the given big array of specified index.
      static double get​(double[][] array, long index)
      Returns the element of the given big array of specified index.
      static float get​(float[][] array, long index)
      Returns the element of the given big array of specified index.
      static int get​(int[][] array, long index)
      Returns the element of the given big array of specified index.
      static long get​(long[][] array, long index)
      Returns the element of the given big array of specified index.
      static short get​(short[][] array, long index)
      Returns the element of the given big array of specified index.
      static <K> K get​(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 void incr​(byte[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(char[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(double[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(float[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(int[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(long[][] array, long index)
      Increments the element of the given big array of specified index.
      static void incr​(short[][] array, long index)
      Increments the element of the given big array of specified index.
      static long index​(int segment, int displacement)
      Computes the index associated with given segment and displacement.
      static long length​(boolean[][] array)
      Returns the length of the given big array.
      static long length​(byte[][] array)
      Returns the length of the given big array.
      static long length​(char[][] array)
      Returns the length of the given big array.
      static long length​(double[][] array)
      Returns the length of the given big array.
      static long length​(float[][] array)
      Returns the length of the given big array.
      static long length​(int[][] array)
      Returns the length of the given big array.
      static long length​(long[][] array)
      Returns the length of the given big array.
      static long length​(short[][] array)
      Returns the length of the given big array.
      static <K> long length​(K[][] array)
      Returns the length of the given big array.
      static void main​(String[] arg)  
      static void mergeSort​(long from, long to, LongComparator comp, BigSwapper swapper)
      Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using mergesort.
      static void mul​(byte[][] array, long index, byte factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(char[][] array, long index, char factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(double[][] array, long index, double factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(float[][] array, long index, float factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(int[][] array, long index, int factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(long[][] array, long index, long factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void mul​(short[][] array, long index, short factor)
      Multiplies by the specified factor the element of the given big array of specified index.
      static void quickSort​(long from, long to, LongComparator comp, BigSwapper swapper)
      Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using quicksort.
      static int segment​(long index)
      Computes the segment associated with a given index.
      static void set​(boolean[][] array, long index, boolean value)
      Sets the element of the given big array of specified index.
      static void set​(byte[][] array, long index, byte value)
      Sets the element of the given big array of specified index.
      static void set​(char[][] array, long index, char value)
      Sets the element of the given big array of specified index.
      static void set​(double[][] array, long index, double value)
      Sets the element of the given big array of specified index.
      static void set​(float[][] array, long index, float value)
      Sets the element of the given big array of specified index.
      static void set​(int[][] array, long index, int value)
      Sets the element of the given big array of specified index.
      static void set​(long[][] array, long index, long value)
      Sets the element of the given big array of specified index.
      static void set​(short[][] array, long index, short value)
      Sets the element of the given big array of specified index.
      static <K> void set​(K[][] array, long index, K value)
      Sets the element of the given big array of specified index.
      static boolean[][] setLength​(boolean[][] array, long length)
      Sets the length of the given big array.
      static byte[][] setLength​(byte[][] array, long length)
      Sets the length of the given big array.
      static char[][] setLength​(char[][] array, long length)
      Sets the length of the given big array.
      static double[][] setLength​(double[][] array, long length)
      Sets the length of the given big array.
      static float[][] setLength​(float[][] array, long length)
      Sets the length of the given big array.
      static int[][] setLength​(int[][] array, long length)
      Sets the length of the given big array.
      static long[][] setLength​(long[][] array, long length)
      Sets the length of the given big array.
      static short[][] setLength​(short[][] array, long length)
      Sets the length of the given big array.
      static <K> K[][] setLength​(K[][] array, long length)
      Sets the length of the given big array.
      static long start​(int segment)
      Computes the starting index of a given segment.
      static void swap​(boolean[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(byte[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(char[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(double[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(float[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(int[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(long[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static void swap​(short[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static <K> void swap​(K[][] array, long first, long second)
      Swaps the element of the given big array of specified indices.
      static String toString​(boolean[][] a)  
      static String toString​(byte[][] a)  
      static String toString​(char[][] a)  
      static String toString​(double[][] a)  
      static String toString​(float[][] a)  
      static String toString​(int[][] a)  
      static String toString​(long[][] a)  
      static String toString​(short[][] a)  
      static <K> String toString​(K[][] a)  
      static boolean[][] trim​(boolean[][] array, long length)
      Trims the given big array to the given length.
      static byte[][] trim​(byte[][] array, long length)
      Trims the given big array to the given length.
      static char[][] trim​(char[][] array, long length)
      Trims the given big array to the given length.
      static double[][] trim​(double[][] array, long length)
      Trims the given big array to the given length.
      static float[][] trim​(float[][] array, long length)
      Trims the given big array to the given length.
      static int[][] trim​(int[][] array, long length)
      Trims the given big array to the given length.
      static long[][] trim​(long[][] array, long length)
      Trims the given big array to the given length.
      static short[][] trim​(short[][] array, long length)
      Trims the given big array to the given length.
      static <K> K[][] trim​(K[][] array, long length)
      Trims the given big array to the given length.
      static boolean[][] wrap​(boolean[] array)
      Turns a standard array into a big array.
      static byte[][] wrap​(byte[] array)
      Turns a standard array into a big array.
      static char[][] wrap​(char[] array)
      Turns a standard array into a big array.
      static double[][] wrap​(double[] array)
      Turns a standard array into a big array.
      static float[][] wrap​(float[] array)
      Turns a standard array into a big array.
      static int[][] wrap​(int[] array)
      Turns a standard array into a big array.
      static long[][] wrap​(long[] array)
      Turns a standard array into a big array.
      static short[][] wrap​(short[] array)
      Turns a standard array into a big array.
      static <K> K[][] wrap​(K[] array)
      Turns a standard array into a big array.
    • Field Detail

      • SEGMENT_SHIFT

        public static final int SEGMENT_SHIFT
        The 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_SIZE
        The current size of a segment (227) is the largest size that makes the physical memory allocation for a single segment strictly smaller than 231 bytes.
        See Also:
        Constant Field Values
      • SEGMENT_MASK

        public static final int SEGMENT_MASK
        The mask used to compute the displacement associated to an index.
        See Also:
        Constant Field Values
    • Method Detail

      • 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.
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than bigArrayLength or 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 fragment
        length - a length (the number of elements in the fragment).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset + length is greater than bigArrayLength.
      • ensureLength

        public static void ensureLength​(long bigArrayLength)
        Ensures that a big-array length is legal.
        Parameters:
        bigArrayLength - a big-array length.
        Throws:
        IllegalArgumentException - if length is negative, or larger than or equal to SEGMENT_SIZE * Integer.MAX_VALUE.
      • mergeSort

        public static void mergeSort​(long from,
                                     long to,
                                     LongComparator comp,
                                     BigSwapper swapper)
        Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using mergesort.

        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

        public static void quickSort​(long from,
                                     long to,
                                     LongComparator comp,
                                     BigSwapper swapper)
        Sorts the specified range of elements using the specified big swapper and according to the order induced by the specified comparator using quicksort.

        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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static byte[][] forceCapacity​(byte[][] array,
                                             long length,
                                             long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static byte[][] copy​(byte[][] array,
                                    long offset,
                                    long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static byte[][] copy​(byte[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(byte[][] array,
                                byte value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(byte[][] array,
                                long from,
                                long to,
                                byte value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(byte[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(byte[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(byte[][] a,
                                            byte[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static int[][] forceCapacity​(int[][] array,
                                            long length,
                                            long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static int[][] copy​(int[][] array,
                                   long offset,
                                   long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static int[][] copy​(int[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(int[][] array,
                                int value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(int[][] array,
                                long from,
                                long to,
                                int value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(int[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(int[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(int[][] a,
                                            int[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static long[][] forceCapacity​(long[][] array,
                                             long length,
                                             long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static long[][] copy​(long[][] array,
                                    long offset,
                                    long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static long[][] copy​(long[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(long[][] array,
                                long value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(long[][] array,
                                long from,
                                long to,
                                long value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(long[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(long[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(long[][] a,
                                            long[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static double[][] forceCapacity​(double[][] array,
                                               long length,
                                               long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static double[][] copy​(double[][] array,
                                      long offset,
                                      long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static double[][] copy​(double[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(double[][] array,
                                double value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(double[][] array,
                                long from,
                                long to,
                                double value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(double[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(double[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(double[][] a,
                                            double[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static boolean[][] forceCapacity​(boolean[][] array,
                                                long length,
                                                long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static boolean[][] copy​(boolean[][] array,
                                       long offset,
                                       long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static boolean[][] copy​(boolean[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(boolean[][] array,
                                boolean value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(boolean[][] array,
                                long from,
                                long to,
                                boolean value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(boolean[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(boolean[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(boolean[][] a,
                                            boolean[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static short[][] forceCapacity​(short[][] array,
                                              long length,
                                              long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static short[][] copy​(short[][] array,
                                     long offset,
                                     long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static short[][] copy​(short[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(short[][] array,
                                short value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(short[][] array,
                                long from,
                                long to,
                                short value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(short[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(short[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(short[][] a,
                                            short[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static char[][] forceCapacity​(char[][] array,
                                             long length,
                                             long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static char[][] copy​(char[][] array,
                                    long offset,
                                    long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static char[][] copy​(char[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(char[][] array,
                                char value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(char[][] array,
                                long from,
                                long to,
                                char value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(char[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(char[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(char[][] a,
                                            char[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static float[][] forceCapacity​(float[][] array,
                                              long length,
                                              long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static float[][] copy​(float[][] array,
                                     long offset,
                                     long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static float[][] copy​(float[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static void fill​(float[][] array,
                                float value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static void fill​(float[][] array,
                                long from,
                                long to,
                                float value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static String toString​(float[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static void ensureOffsetLength​(float[][] a,
                                              long offset,
                                              long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static void ensureSameLength​(float[][] a,
                                            float[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • 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.
      • 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 contains length entries or more; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • forceCapacity

        public static <K> K[][] forceCapacity​(K[][] array,
                                              long length,
                                              long preserve)
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        This method returns a new big array of the given length whose element are of the same class as of those of array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries or more; otherwise, a big array with length entries whose first preserve entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first length(array) entries are the same as those of array.
      • 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 contain length entries; otherwise, a big array with max(length,length(array)/φ) entries whose first preserve entries are the same as those of array.
      • 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 contains length entries or less; otherwise, a big array with length entries whose entries are the same as the first length entries of array.
      • 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 exactly length entries; otherwise, if it contains more than length entries, a big array with length entries whose entries are the same as the first length entries of array; otherwise, a big array with length entries whose first length(array) entries are the same as those of array.
      • copy

        public static <K> K[][] copy​(K[][] array,
                                     long offset,
                                     long length)
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        public static <K> K[][] copy​(K[][] array)
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        public static <K> void fill​(K[][] array,
                                    K value)
        Fills the given big array with the given value.

        This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        public static <K> void fill​(K[][] array,
                                    long from,
                                    long to,
                                    K value)
        Fills a portion of the given big array with the given value.

        If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

        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

        public static <K> String toString​(K[][] a)
      • 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 - if from is greater than to.
        ArrayIndexOutOfBoundsException - if from or to are greater than the big array length or negative.
      • ensureOffsetLength

        public static <K> void ensureOffsetLength​(K[][] a,
                                                  long offset,
                                                  long length)
        Ensures that a range given by an offset and a length fits a big array.

        This method may be used whenever a big array range check is needed.

        Parameters:
        a - a big array.
        offset - a start index.
        length - a length (the number of elements in the range).
        Throws:
        IllegalArgumentException - if length is negative.
        ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the big array length.
      • ensureSameLength

        public static <K> void ensureSameLength​(K[][] a,
                                                K[][] b)
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • main

        public static void main​(String[] arg)