@Override public void clear() { size = 0; assert size <= LongBigArrays.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 LongBigArrayBigList(final long a[][]) { this(a, 0, LongBigArrays.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 LongBigArrayBigList wrap(final long a[][], final long length) { if (length > LongBigArrays.length(a)) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + LongBigArrays.length(a) + ")"); final LongBigArrayBigList l = new LongBigArrayBigList(a, false); l.size = length; return l; } /**
/** 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 loadLongs(final CharSequence filename, final long[][] array) throws IOException { return loadLongs(filename, array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array)); } /** Stores a big-array fragment to a given print stream.
/** 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 storeLongs(final long array[][], final CharSequence filename) throws IOException { storeLongs(array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array), filename); } /** A wrapper that exhibits the content of a reader as a type-specific iterator. */
/** * 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 LongBigArrayBigList wrap(final long a[][]) { return wrap(a, LongBigArrays.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 loadLongs(final BufferedReader reader, final long[][] array) throws IOException { return loadLongs(reader, array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array)); } /** Loads elements from a file given by a {@link File} object, storing them in a given big-array fragment.
/** 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 storeLongs(final long array[][], final File file) throws IOException { storeLongs(array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array), file); } /** Stores a big array to a file given by a pathname.
/** * {@inheritDoc} * * <p> * This implementation delegates to the analogous method for big-array * fragments. */ @Override public void addElements(final long index, final long a[][]) { addElements(index, a, 0, LongBigArrays.length(a)); } /**
/** 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 loadLongs(final File file, final long[][] array) throws IOException { return loadLongs(file, array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array)); } /** Loads elements from a file given by a filename, storing them in a given array.
/** 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 storeLongs(final long array[][], final PrintStream stream) { storeLongs(array, 0, it.unimi.dsi.fastutil.longs.LongBigArrays.length(array), stream); } /** Stores a big-array fragment to a file given by a {@link File} object.
/** * 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 == LongBigArrays.DEFAULT_EMPTY_BIG_ARRAY) return; a = LongBigArrays.forceCapacity(a, capacity, size); assert size <= LongBigArrays.length(a); } /**
public static String toString(final long[][] 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 long[][] x) { quickSort(x, 0, LongBigArrays.length(x)); } /**
@Override public long removeLong(final long index) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); final long old = LongBigArrays.get(a, index); size--; if (index != size) LongBigArrays.copy(a, index + 1, a, index, size - index); assert size <= LongBigArrays.length(a); return old; } @Override
@Override public boolean add(final long k) { grow(size + 1); LongBigArrays.set(a, size++, k); assert size <= LongBigArrays.length(a); return true; } @Override
@Override public void size(final long size) { if (size > LongBigArrays.length(a)) a = LongBigArrays.forceCapacity(a, size, this.size); if (size > this.size) LongBigArrays.fill(a, this.size, size, (0)); this.size = size; } @Override
@Override public boolean rem(final long k) { final long index = indexOf(k); if (index == -1) return false; removeLong(index); assert size <= LongBigArrays.length(a); return true; } @Override
/** Computes the inverse of a permutation expressed * as a {@linkplain BigArrays big array} of <var>n</var> distinct long integers in [0 .. <var>n</var>) * and stores the result in a new big array. * * <p><strong>Warning</strong>: if <code>perm</code> is not a permutation, * essentially anything can happen. * * @param perm the permutation to be inverted. * @return a new big array containing the inverse permutation. */ public static long[][] invertPermutation(long[][] perm) { return invertPermutation(perm, LongBigArrays.newBigArray(LongBigArrays.length(perm))); }
@Override public void add(final long index, final long k) { ensureIndex(index); grow(size + 1); if (index != size) LongBigArrays.copy(a, index, a, index + 1, size - index); LongBigArrays.set(a, index, k); size++; assert size <= LongBigArrays.length(a); } @Override