@Override public void getElements(long from, long[][] a, long offset, long length) { LongBigArrays.ensureOffsetLength(a, offset, length); if (from != 0) throw new IndexOutOfBoundsException(); } @Override
/** Stores a big-array fragment to a given print stream. * * @param array a big array whose elements will be written to {@code stream}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param stream a print stream. */ public static void storeLongs(final long array[][], final long offset, final long length, final PrintStream stream) { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) stream.println(t[d]); } } /** Stores a big array to a given print stream.
/** * 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 long[][] copy(final long[][] array, final long offset, final long length) { ensureOffsetLength(array, offset, length); final long[][] a = newBigArray(length); copy(array, offset, a, 0, length); return a; } /**
/** Stores an array fragment to a given data output. * * @param array an array whose elements will be written to {@code dataOutput}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param dataOutput a data output. */ public static void storeLongs(final long array[][], final long offset, final long length, final DataOutput dataOutput) throws IOException { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) dataOutput.writeLong(t[d]); } } /** Stores a big array to a given data output.
/** Stores a big-array fragment to a file given by a {@link File} object. * * @param array a big array whose elements will be written to {@code filename}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param file a file. */ public static void storeLongs(final long array[][], final long offset, final long length, final File file) throws IOException { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); final DataOutputStream dos = new DataOutputStream(new FastBufferedOutputStream(new FileOutputStream(file))); for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) dos.writeLong(t[d]); } dos.close(); } /** Stores a big-array fragment to a file given by a pathname.
/** Loads elements from a given fast buffered reader, storing them in a given big-array fragment. * * @param reader a buffered reader. * @param array a big array which will be filled with data from {@code reader}. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from {@code reader} (it might be less than {@code length} if {@code reader} ends). */ public static long loadLongs(final BufferedReader reader, final long[][] array, final long offset, final long length) throws IOException { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); long c = 0; String s; try { for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) { if ((s = reader.readLine()) != null) t[d] = Long.parseLong(s.trim()); else return c; c++; } } } catch(EOFException itsOk) {} return c; } /** Loads elements from a given buffered reader, storing them in a given array.
/** Loads elements from a given data input, storing them in a given big-array fragment. * * @param dataInput a data input. * @param array a big array which will be filled with data from {@code dataInput}. * @param offset the index of the first element of {@code bigArray} to be filled. * @param length the number of elements of {@code bigArray} to be filled. * @return the number of elements actually read from {@code dataInput} (it might be less than {@code length} if {@code dataInput} ends). */ public static long loadLongs(final DataInput dataInput, final long[][] array, final long offset, final long length) throws IOException { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); long c = 0; try { for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) { t[d] = dataInput.readLong(); c++; } } } catch(EOFException itsOk) {} return c; } /** Loads elements from a given data input, storing them in a given big array.
/** * {@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 addElements(long index, final long a[][], long offset, long length) { ensureIndex(index); LongBigArrays.ensureOffsetLength(a, offset, length); while (length-- != 0) add(index++, LongBigArrays.get(a, offset++)); } /**
/** Loads elements from a file given by a {@link File} object, storing them in a given big-array fragment. * * @param file a file. * @param array a big array which will be filled with data from the specified file. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from the given file (it might be less than {@code length} if the file is too short). */ public static long loadLongs(final File file, final long[][] array, final long offset, final long length) throws IOException { it.unimi.dsi.fastutil.longs.LongBigArrays.ensureOffsetLength(array, offset, length); final FileInputStream fis = new FileInputStream(file); final DataInputStream dis = new DataInputStream(new FastBufferedInputStream(fis)); long c = 0; try { for(int i = segment(offset); i < segment(offset + length + SEGMENT_MASK); i++) { final long[] t = array[i]; final int l = (int)Math.min(t.length, offset + length - start(i)); for(int d = (int)Math.max(0, offset - start(i)); d < l; d++) { t[d] = dis.readLong(); c++; } } } catch(EOFException itsOk) {} dis.close(); return c; } /** Loads elements from a file given by a pathname, storing them in a given big-array fragment.
/** * {@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 long a[][], long offset, long length) { LongBigListIterator i = listIterator(from); LongBigArrays.ensureOffsetLength(a, offset, length); if (from + length > size64()) throw new IndexOutOfBoundsException( "End index (" + (from + length) + ") is greater than list size (" + size64() + ")"); while (length-- != 0) LongBigArrays.set(a, offset++, i.nextLong()); } /**
/** * Adds elements to this type-specific list using optimized system calls. * * @param index * the index at which to add elements. * @param a * the big array containing the elements. * @param offset * the offset of the first element to add. * @param length * the number of elements to add. */ @Override public void addElements(final long index, final long a[][], final long offset, final long length) { ensureIndex(index); LongBigArrays.ensureOffsetLength(a, offset, length); grow(size + length); LongBigArrays.copy(this.a, index, this.a, index + length, size - index); LongBigArrays.copy(a, offset, this.a, index, length); size += length; } @Override