/** Stores an array fragment to a given print stream. * * @param array an 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 storeBooleans(final boolean array[], final int offset, final int length, final PrintStream stream) { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); for(int i = 0; i < length; i++) stream.println(array[offset + i]); } /** Stores an array to a given print stream.
/** 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 storeBooleans(final boolean array[], final int offset, final int length, final DataOutput dataOutput) throws IOException { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); for(int i = 0; i < length; i++) dataOutput.writeBoolean(array[offset + i]); } /** Stores an array to a given data output.
/** Loads elements from a given data input, storing them in a given array fragment. * * @param dataInput a data input. * @param array an array which will be filled with data from {@code dataInput}. * @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 dataInput} (it might be less than {@code length} if {@code dataInput} ends). */ public static int loadBooleans(final DataInput dataInput, final boolean[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); int i = 0; try { for(i = 0; i < length; i++) array[i + offset] = dataInput.readBoolean(); } catch(EOFException itsOk) {} return i; } /** Loads elements from a given data input, storing them in a given array.
/** Returns a copy of a portion of an array. * * @param array an array. * @param offset the first element to copy. * @param length the number of elements to copy. * @return a new array containing <code>length</code> elements of <code>array</code> starting at <code>offset</code>. */ public static boolean[] copy( final boolean[] array, final int offset, final int length ) { ensureOffsetLength( array, offset, length ); final boolean[] a = length == 0 ? EMPTY_ARRAY : new boolean[ length ]; System.arraycopy( array, offset, a, 0, length ); return a; } /** Returns a copy of an array.
/** * Copies element of this type-specific list into the given array using * optimized system calls. * * @param from * the start index (inclusive). * @param a * the destination array. * @param offset * the offset into the destination array where to store the first * element copied. * @param length * the number of elements to be copied. */ @Override public void getElements(final int from, final boolean[] a, final int offset, final int length) { BooleanArrays.ensureOffsetLength(a, offset, length); System.arraycopy(this.a, from, a, offset, length); } /**
/** * Returns a copy of a portion of an array. * * @param array * an array. * @param offset * the first element to copy. * @param length * the number of elements to copy. * @return a new array containing {@code length} elements of {@code array} * starting at {@code offset}. */ public static boolean[] copy(final boolean[] array, final int offset, final int length) { ensureOffsetLength(array, offset, length); final boolean[] a = length == 0 ? EMPTY_ARRAY : new boolean[length]; System.arraycopy(array, offset, a, 0, length); return a; } /**
/** Loads elements from a given fast buffered reader, storing them in a given array fragment. * * @param reader a buffered reader. * @param array an 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 int loadBooleans(final BufferedReader reader, final boolean[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); int i = 0; String s; try { for(i = 0; i < length; i++) if ((s = reader.readLine()) != null) array[i + offset] = Boolean.parseBoolean(s.trim()); else break; } catch(EOFException itsOk) {} return i; } /** Loads elements from a given buffered reader, storing them in a given array.
/** Stores an array fragment to a file given by a {@link File} object. * * @param array an 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 storeBooleans(final boolean array[], final int offset, final int length, final File file) throws IOException { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); final DataOutputStream dos = new DataOutputStream(new FastBufferedOutputStream(new FileOutputStream(file))); for(int i = 0; i < length; i++) dos.writeBoolean(array[offset + i]); dos.close(); } /** Stores an array fragment to a file given by a pathname.
/** * Creates a new hash set and fills it with the elements of a given array. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param f * the load factor. */ public BooleanOpenHashSet(final boolean[] a, final int offset, final int length, final float f) { this(length < 0 ? 0 : length, f); BooleanArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** * Wraps the given part of an array into a type-specific list iterator. * * <p> * The type-specific list iterator returned by this method will iterate * {@code length} times, returning consecutive elements of the given array * starting from the one with index {@code offset}. * * @param array * an array to wrap into a type-specific list iterator. * @param offset * the first element of the array to be returned. * @param length * the number of elements to return. * @return an iterator that will return {@code length} elements of {@code array} * starting at position {@code offset}. */ public static BooleanListIterator wrap(final boolean[] array, final int offset, final int length) { BooleanArrays.ensureOffsetLength(array, offset, length); return new ArrayIterator(array, offset, length); } /**
/** Loads elements from a file given by a {@link File} object, storing them in a given array fragment. * * @param file a file. * @param array an 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 int loadBooleans(final File file, final boolean[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.booleans.BooleanArrays.ensureOffsetLength(array, offset, length); final FileInputStream fis = new FileInputStream(file); final DataInputStream dis = new DataInputStream(new FastBufferedInputStream(fis)); int i = 0; try { for(i = 0; i < length; i++) array[i + offset] = dis.readBoolean(); } catch(EOFException itsOk) {} dis.close(); return i; } /** Loads elements from a file given by a pathname, storing them in a given array fragment.
/** * Adds elements to this type-specific list using optimized system calls. * * @param index * the index at which to add elements. * @param a * the 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 int index, final boolean a[], final int offset, final int length) { ensureIndex(index); BooleanArrays.ensureOffsetLength(a, offset, length); grow(size + length); System.arraycopy(this.a, index, this.a, index + length, size - index); System.arraycopy(a, offset, this.a, index, length); size += length; } @Override