@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
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 fragment using the specified pseudorandom * number generator. * * @param a * the big array to be shuffled. * @param from * the index of the first element (inclusive) to be shuffled. * @param to * the index of the last element (exclusive) to be shuffled. * @param random * a pseudorandom number generator. * @return {@code a}. */ public static boolean[][] shuffle(final boolean[][] a, final long from, final long to, final Random random) { for (long i = to - from; i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final boolean t = get(a, from + i); set(a, from + i, get(a, from + p)); set(a, from + p, t); } return a; } /**
@Override public boolean add(final boolean k) { grow(size + 1); BooleanBigArrays.set(a, size++, k); assert size <= BooleanBigArrays.length(a); return true; } @Override
/** * 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 void add(final long index, final boolean k) { ensureIndex(index); grow(size + 1); if (index != size) BooleanBigArrays.copy(a, index, a, index + 1, size - index); BooleanBigArrays.set(a, index, k); size++; assert size <= BooleanBigArrays.length(a); } @Override
/** * {@inheritDoc} * * <p> * This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. */ @Override public void getElements(final long from, final boolean a[][], long offset, long length) { BooleanBigListIterator i = listIterator(from); BooleanBigArrays.ensureOffsetLength(a, offset, length); if (from + length > size64()) throw new IndexOutOfBoundsException( "End index (" + (from + length) + ") is greater than list size (" + size64() + ")"); while (length-- != 0) BooleanBigArrays.set(a, offset++, i.nextBoolean()); } /**