@Override public void clear() { size = 0; assert size <= BooleanBigArrays.length(a); } @Override
/** * Creates a new big-array big list and fills it with the elements of a given * big array. * * <p> * Note that this constructor makes it easy to build big lists from literal * arrays declared as * <code><var>type</var>[][] {{ <var>init_values</var> }}</code>. The only * constraint is that the number of initialisation values is below * {@link it.unimi.dsi.fastutil.BigArrays#SEGMENT_SIZE}. * * @param a * a big array whose elements will be used to fill the array list. */ public BooleanBigArrayBigList(final boolean a[][]) { this(a, 0, BooleanBigArrays.length(a)); } /**
/** * Wraps a given big array into a big-array list of given size. * * @param a * a big array to wrap. * @param length * the length of the resulting big-array list. * @return a new big-array list of the given size, wrapping the given big array. */ public static BooleanBigArrayBigList wrap(final boolean a[][], final long length) { if (length > BooleanBigArrays.length(a)) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + BooleanBigArrays.length(a) + ")"); final BooleanBigArrayBigList l = new BooleanBigArrayBigList(a, false); l.size = length; return l; } /**
/** Loads elements from a file given by a {@link File} object, storing them in a given array. * * @param file a file. * @param array a big array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static long loadBooleans(final File file, final boolean[][] array) throws IOException { return loadBooleans(file, array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array)); } /** Loads elements from a file given by a filename, storing them in a given array.
/** Stores a big array to a file given by a pathname. * * @param array a big array whose elements will be written to {@code filename}. * @param filename a filename. */ public static void storeBooleans(final boolean array[][], final CharSequence filename) throws IOException { storeBooleans(array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array), filename); } /** A wrapper that exhibits the content of a reader as a type-specific iterator. */
/** * Grows this big-array big list, ensuring that it can contain the given number * of entries without resizing, and in case increasing current capacity at least * by a factor of 50%. * * @param capacity * the new minimum capacity for this big-array big list. */ private void grow(long capacity) { final long oldLength = BooleanBigArrays.length(a); if (capacity <= oldLength) return; if (a != BooleanBigArrays.DEFAULT_EMPTY_BIG_ARRAY) capacity = Math.max(oldLength + (oldLength >> 1), capacity); else if (capacity < DEFAULT_INITIAL_CAPACITY) capacity = DEFAULT_INITIAL_CAPACITY; a = BooleanBigArrays.forceCapacity(a, capacity, size); assert size <= BooleanBigArrays.length(a); } @Override
/** Stores a big array to a given print stream. * * @param array a big array whose elements will be written to {@code stream}. * @param stream a print stream. */ public static void storeBooleans(final boolean array[][], final PrintStream stream) { storeBooleans(array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array), stream); } /** Stores a big-array fragment to a file given by a {@link File} object.
/** * {@inheritDoc} * * <p> * This implementation delegates to the analogous method for big-array * fragments. */ @Override public void addElements(final long index, final boolean a[][]) { addElements(index, a, 0, BooleanBigArrays.length(a)); } /**
/** Stores a big array to a file given by a {@link File} object. * * @param array a big array whose elements will be written to {@code filename}. * @param file a file. */ public static void storeBooleans(final boolean array[][], final File file) throws IOException { storeBooleans(array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array), file); } /** Stores a big array to a file given by a pathname.
/** * Wraps a given big array into a big-array big list. * * @param a * a big array to wrap. * @return a new big-array big list wrapping the given array. */ public static BooleanBigArrayBigList wrap(final boolean a[][]) { return wrap(a, BooleanBigArrays.length(a)); } /**
/** Loads elements from a given buffered reader, storing them in a given array. * * @param reader a buffered reader. * @param array a big array which will be filled with data from {@code reader}. * @return the number of elements actually read from {@code reader} (it might be less than the array length if {@code reader} ends). */ public static long loadBooleans(final BufferedReader reader, final boolean[][] array) throws IOException { return loadBooleans(reader, array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array)); } /** Loads elements from a file given by a {@link File} object, storing them in a given big-array fragment.
/** Loads elements from a file given by a filename, storing them in a given array. * * @param filename a filename. * @param array a big array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static long loadBooleans(final CharSequence filename, final boolean[][] array) throws IOException { return loadBooleans(filename, array, 0, it.unimi.dsi.fastutil.booleans.BooleanBigArrays.length(array)); } /** Stores a big-array fragment to a given print stream.
/** * 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); } /**
public static String toString(final boolean[][] a) { if (a == null) return "null"; final long last = length(a) - 1; if (last == -1) return "[]"; final StringBuilder b = new StringBuilder(); b.append('['); for (long i = 0;; i++) { b.append(String.valueOf(get(a, i))); if (i == last) return b.append(']').toString(); b.append(", "); } } /**
/** * 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)); } /**
@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
@Override public boolean add(final boolean k) { grow(size + 1); BooleanBigArrays.set(a, size++, k); assert size <= BooleanBigArrays.length(a); return true; } @Override
@Override public boolean rem(final boolean k) { final long index = indexOf(k); if (index == -1) return false; removeBoolean(index); assert size <= BooleanBigArrays.length(a); return true; } @Override
@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
@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