/** * Creates a new big-array big list with given capacity. * * @param capacity * the initial capacity of the array list (may be 0). */ public DoubleBigArrayBigList(final long capacity) { if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative"); if (capacity == 0) a = DoubleBigArrays.EMPTY_BIG_ARRAY; else a = DoubleBigArrays.newBigArray(capacity); } /**
/** * Turns a standard array into a big array. * * <p> * Note that the returned big array might contain as a segment the original * array. * * @param array * an array. * @return a new big array with the same length and content of {@code array}. */ public static double[][] wrap(final double[] array) { if (array.length == 0) return EMPTY_BIG_ARRAY; if (array.length <= SEGMENT_SIZE) return new double[][]{array}; final double[][] bigArray = newBigArray(array.length); for (int i = 0; i < bigArray.length; i++) System.arraycopy(array, (int) start(i), bigArray[i], 0, bigArray[i].length); return bigArray; } /**
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = DoubleBigArrays.newBigArray(size); for (int i = 0; i < size; i++) DoubleBigArrays.set(a, i, s.readDouble()); } }
/** Loads elements from a file given by a {@link File} object, storing them in a new big array. * * <p>Note that the length of the returned big array will be computed * dividing the specified file size by the number of bytes used to * represent each element. * * @param file a file. * @return a big array filled with the content of the specified file. */ public static double[][] loadDoublesBig(final File file) throws IOException { final FileInputStream fis = new FileInputStream(file); final long length = fis.getChannel().size() / (Double.SIZE / 8); final double[][] array = DoubleBigArrays.newBigArray(length); final DataInputStream dis = new DataInputStream(new FastBufferedInputStream(fis)); for(int i = 0; i < array.length; i++) { final double[] t = array[i]; final int l = t.length; for(int d = 0; d < l; d++) t[d] = dis.readDouble(); } dis.close(); return array; } /** Loads elements from a file given by a filename, storing them in a new big array.
/** * 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 double[][] copy(final double[][] array, final long offset, final long length) { ensureOffsetLength(array, offset, length); final double[][] a = newBigArray(length); copy(array, offset, a, 0, length); return a; } /**
/** * Creates a new hash big set. * * <p> * The actual table size will be the least power of two greater than * {@code expected}/{@code f}. * * @param expected * the expected number of elements in the set. * @param f * the load factor. */ public DoubleOpenHashBigSet(final long expected, final float f) { if (f <= 0 || f > 1) throw new IllegalArgumentException("Load factor must be greater than 0 and smaller than or equal to 1"); if (n < 0) throw new IllegalArgumentException("The expected number of elements must be nonnegative"); this.f = f; minN = n = bigArraySize(expected, f); maxFill = maxFill(n, f); key = DoubleBigArrays.newBigArray(n); initMasks(); } /**
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); n = bigArraySize(size, f); maxFill = maxFill(n, f); final double[][] key = this.key = DoubleBigArrays.newBigArray(n); initMasks(); long h; double k; int base, displ; for (long i = size; i-- != 0;) { k = s.readDouble(); if ((Double.doubleToLongBits(k) == 0)) containsNull = true; else { h = it.unimi.dsi.fastutil.HashCommon.mix(Double.doubleToRawLongBits(k)); if (!(Double .doubleToLongBits(key[base = (int) ((h & mask) >>> BigArrays.SEGMENT_SHIFT)][displ = (int) (h & segmentMask)]) == 0)) while (!(Double .doubleToLongBits(key[base = (base + ((displ = (displ + 1) & segmentMask) == 0 ? 1 : 0)) & baseMask][displ]) == 0)); key[base][displ] = k; } } if (ASSERTS) checkTable(); } private void checkTable() {
this.score = DoubleBigArrays.newBigArray( score.size64() ); DoubleBigArrays.copy( score.elements(), 0, this.score, 0, score.size64() ); score = DoubleBigArrays.newBigArray( n ); if ( type.equals( "int" ) ) for( int i = 0; i < n; i++ ) DoubleBigArrays.set( score, i, dis.readInt() ); else if ( type.equals( "long" ) ) for( int i = 0; i < n; i++ ) DoubleBigArrays.set( score, i, dis.readLong() );
final double newKey[][] = DoubleBigArrays.newBigArray(newN); final long mask = newN - 1; // Note that this is used by the hashing macro final int newSegmentMask = newKey[0].length - 1;