/** * Returns a copy of a portion of a big array. * * @param array * a big array. * @param offset * the first element to copy. * @param length * the number of elements to copy. * @return a new big array containing {@code length} elements of {@code array} * starting at {@code offset}. */ public static boolean[][] copy(final boolean[][] array, final long offset, final long length) { ensureOffsetLength(array, offset, length); final boolean[][] a = newBigArray(length); copy(array, offset, a, 0, length); return a; } /**
/** * Sets the length of the given big array. * * <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 length for the big array. * @return {@code array}, if it contains exactly {@code length} entries; * otherwise, if it contains <em>more</em> than {@code length} entries, * a big array with {@code length} entries whose entries are the same as * the first {@code length} entries of {@code array}; otherwise, a big * array with {@code length} entries whose first {@code length(array)} * entries are the same as those of {@code array}. * */ public static boolean[][] setLength(final boolean[][] array, final long length) { final long oldLength = length(array); if (length == oldLength) return array; if (length < oldLength) return trim(array, length); return ensureCapacity(array, length); } /**
@Override public boolean equals(final boolean[][] a, final boolean[][] b) { return BooleanBigArrays.equals(a, b); } }
@Override public void size(final long size) { if (size > BooleanBigArrays.length(a)) a = BooleanBigArrays.forceCapacity(a, size, this.size); if (size > this.size) BooleanBigArrays.fill(a, this.size, size, (false)); this.size = size; } @Override
/** * Ensures that this big-array big list can contain the given number of entries * without resizing. * * @param capacity * the new minimum capacity for this big-array big list. */ public void ensureCapacity(final long capacity) { if (capacity <= a.length || a == BooleanBigArrays.DEFAULT_EMPTY_BIG_ARRAY) return; a = BooleanBigArrays.forceCapacity(a, capacity, size); assert size <= BooleanBigArrays.length(a); } /**
selectionSort(x, from, to, comp); return; if (len > MEDIUM) { // Big arrays, pseudomedian of 9 long s = len / 8; l = med3(x, l, l + s, l + 2 * s, comp); m = med3(x, m - s, m, m + s, comp); n = med3(x, n - 2 * s, n - s, n, comp); m = med3(x, l, m, n, comp); // Mid-size, med of 3 final boolean v = get(x, m); while (b <= c && (comparison = comp.compare(get(x, b), v)) <= 0) { if (comparison == 0) swap(x, a++, b); b++; while (c >= b && (comparison = comp.compare(get(x, c), v)) >= 0) { if (comparison == 0) swap(x, c, d--); c--; swap(x, b++, c--); vecSwap(x, from, b - s, s); s = Math.min(d - c, n - d - 1); vecSwap(x, b, n - s, s);
/** * Creates a new big-array big list with given capacity. * * @param capacity * the initial capacity of the array list (may be 0). */ public BooleanBigArrayBigList(final long capacity) { if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative"); if (capacity == 0) a = BooleanBigArrays.EMPTY_BIG_ARRAY; else a = BooleanBigArrays.newBigArray(capacity); } /**
@Override public void clear() { size = 0; assert size <= BooleanBigArrays.length(a); } @Override
@Override public boolean removeBoolean(final long index) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); final boolean old = BooleanBigArrays.get(a, index); size--; if (index != size) BooleanBigArrays.copy(a, index + 1, a, index, size - index); assert size <= BooleanBigArrays.length(a); return old; } @Override
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = BooleanBigArrays.newBigArray(size); for (int i = 0; i < size; i++) BooleanBigArrays.set(a, i, s.readBoolean()); } }
/** * Shuffles the specified big array using the specified pseudorandom number * generator. * * @param a * the big array to be shuffled. * @param random * a pseudorandom number generator. * @return {@code a}. */ public static boolean[][] shuffle(final boolean[][] a, final Random random) { for (long i = length(a); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final boolean t = get(a, i); set(a, i, get(a, p)); set(a, p, t); } return a; } }
@Override public long indexOf(final boolean k) { for (long i = 0; i < size; i++) if (((k) == (BooleanBigArrays.get(a, i)))) return i; return -1; } @Override
@Override public boolean set(final long index, final boolean k) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); boolean old = BooleanBigArrays.get(a, index); BooleanBigArrays.set(a, index, k); return old; } @Override
/** * Sorts the specified big array according to the natural ascending order using * quicksort. * * <p> * The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. * Douglas McIlroy, “Engineering a Sort Function”, <i>Software: * Practice and Experience</i>, 23(11), pages 1249−1265, 1993. * * @param x * the big array to be sorted. */ public static void quickSort(final boolean[][] x) { quickSort(x, 0, BooleanBigArrays.length(x)); } /**
/** * Ensures that a big array can contain the given number of entries. * * <p> * If you cannot foresee whether this big array will need again to be enlarged, * you should probably use {@code grow()} instead. * * <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 minimum length for this big array. * @return {@code array}, if it contains {@code length} entries or more; * otherwise, a big array with {@code length} entries whose first * {@code length(array)} entries are the same as those of {@code array}. */ public static boolean[][] ensureCapacity(final boolean[][] array, final long length) { return ensureCapacity(array, length, length(array)); } /**
@Override public void getElements(long from, boolean[][] a, long offset, long length) { BooleanBigArrays.ensureOffsetLength(a, offset, length); if (from != 0) throw new IndexOutOfBoundsException(); } @Override
/** * 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. * * <p> * If you want complete control on the big array growth, you should probably use * {@code ensureCapacity()} instead. * * <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 minimum length for this big array. * @return {@code array}, if it can contain {@code length} entries; otherwise, a * big array with max({@code length},{@code length(array)}/φ) * entries whose first {@code length(array)} entries are the same as * those of {@code array}. */ public static boolean[][] grow(final boolean[][] array, final long length) { final long oldLength = length(array); return length > oldLength ? grow(array, length, oldLength) : array; } /**