コード例 #1
0
 /**
  * Fills a portion of the given big array with the given value.
  *
  * <p>If possible (i.e., <code>from</code> is 0) this method uses a backward loop. In this case,
  * it is significantly faster than the corresponding method in {@link java.util.Arrays}.
  *
  * @param array a big array.
  * @param from the starting index of the portion to fill.
  * @param to the end index of the portion to fill.
  * @param value the new value for all elements of the specified portion of the big array.
  */
 public static void fill(final boolean[][] array, final long from, long to, final boolean value) {
   final long length = length(array);
   BigArrays.ensureFromTo(length, from, to);
   int fromSegment = segment(from);
   int toSegment = segment(to);
   int fromDispl = displacement(from);
   int toDispl = displacement(to);
   if (fromSegment == toSegment) {
     BooleanArrays.fill(array[fromSegment], fromDispl, toDispl, value);
     return;
   }
   if (toDispl != 0) BooleanArrays.fill(array[toSegment], 0, toDispl, value);
   while (--toSegment > fromSegment) BooleanArrays.fill(array[toSegment], value);
   BooleanArrays.fill(array[fromSegment], fromDispl, SEGMENT_SIZE, value);
 }
コード例 #2
0
 /**
  * Trims the given big array to the given length.
  *
  * <p><strong>Warning:</strong> the returned array might use part of the segments of the original
  * array, which must be considered read-only after calling this method.
  *
  * @param array a big array.
  * @param length the new maximum length for the big array.
  * @return <code>array</code>, if it contains <code>length</code> entries or less; otherwise, a
  *     big array with <code>length</code> entries whose entries are the same as the first <code>
  *     length</code> entries of <code>array</code>.
  */
 public static boolean[][] trim(final boolean[][] array, final long length) {
   final long oldLength = length(array);
   if (length >= oldLength) return array;
   final int baseLength = (int) ((length + SEGMENT_MASK) / SEGMENT_SIZE);
   final boolean[][] base = Arrays.copyOf(array, baseLength);
   final int residual = (int) (length & SEGMENT_MASK);
   if (residual != 0) base[baseLength - 1] = BooleanArrays.trim(base[baseLength - 1], residual);
   return base;
 }
コード例 #3
0
 /**
  * Fills the given big array with the given value.
  *
  * <p>This method uses a backward loop. It is significantly faster than the corresponding method
  * in {@link java.util.Arrays}.
  *
  * @param array a big array.
  * @param value the new value for all elements of the big array.
  */
 public static void fill(final boolean[][] array, final boolean value) {
   for (int i = array.length; i-- != 0; ) BooleanArrays.fill(array[i], value);
 }