private static long med3(final double x[][], final long a, final long b, final long c) { int ab = (Double.compare((get(x, a)), (get(x, b)))); int ac = (Double.compare((get(x, a)), (get(x, c)))); int bc = (Double.compare((get(x, b)), (get(x, c)))); return (ab < 0 ? (bc < 0 ? b : ac < 0 ? c : a) : (bc > 0 ? b : ac > 0 ? c : a)); }
@Override public double removeDouble(final long index) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); final double old = DoubleBigArrays.get(a, index); size--; if (index != size) DoubleBigArrays.copy(a, index + 1, a, index, size - index); assert size <= DoubleBigArrays.length(a); return old; } @Override
/** * 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; } /**
@Override public void size(final long size) { if (size > DoubleBigArrays.length(a)) a = DoubleBigArrays.forceCapacity(a, size, this.size); if (size > this.size) DoubleBigArrays.fill(a, this.size, size, (0)); this.size = size; } @Override
@Override public double set(final long index, final double k) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); double old = DoubleBigArrays.get(a, index); DoubleBigArrays.set(a, index, k); return old; } @Override
selectionSort(x, from, to); return; if (len > MEDIUM) { // Big arrays, pseudomedian of 9 long s = len / 8; l = med3(x, l, l + s, l + 2 * s); m = med3(x, m - s, m, m + s); n = med3(x, n - 2 * s, n - s, n); m = med3(x, l, m, n); // Mid-size, med of 3 final double v = get(x, m); while (b <= c && (comparison = (Double.compare((get(x, b)), (v)))) <= 0) { if (comparison == 0) swap(x, a++, b); b++; while (c >= b && (comparison = (Double.compare((get(x, c)), (v)))) >= 0) { if (comparison == 0) swap(x, c, d--); c--; swap(x, b++, c--); vecSwap(x, from, b - s, s); s = Math.min(d - c, n - d - 1); vecSwap(x, b, n - s, s);
if (DoubleBigArrays.length(a) != DoubleBigArrays.length(b)) throw new IllegalArgumentException("Array size mismatch."); final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if (length < MEDIUM) { selectionSort(a, b, first, first + length); continue; (byte) (((fixDouble(DoubleBigArrays.get(k, first + i)) >>> shift) & DIGIT_MASK) ^ signMask)); for (long i = length; i-- != 0;) count[ByteBigArrays.get(digit, i) & 0xFF]++; double t = DoubleBigArrays.get(a, i + first); double u = DoubleBigArrays.get(b, i + first); c = ByteBigArrays.get(digit, i) & 0xFF; while ((d = --pos[c]) > i) { double z = t; final int zz = c; t = DoubleBigArrays.get(a, d + first); DoubleBigArrays.set(a, d + first, z); z = u; u = DoubleBigArrays.get(b, d + first); DoubleBigArrays.set(b, d + first, z); c = ByteBigArrays.get(digit, d) & 0xFF; ByteBigArrays.set(digit, d, (byte) zz); DoubleBigArrays.set(a, i + first, t); DoubleBigArrays.set(b, i + first, u);
/** * Shuffles the specified big array using the specified pseudorandom number * generator. * * @param a * the big array to be shuffled. * @param random * a pseudorandom number generator. * @return {@code a}. */ public static double[][] shuffle(final double[][] a, final Random random) { for (long i = length(a); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final double t = get(a, i); set(a, i, get(a, p)); set(a, p, t); } return a; } }
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() ); else if ( type.equals( "float" ) ) for( int i = 0; i < n; i++ ) DoubleBigArrays.set( score, i, dis.readFloat() ); else if ( type.equals( "double" ) ) for( int i = 0; i < n; i++ ) DoubleBigArrays.set( score, i, dis.readDouble() ); else throw new IllegalArgumentException( "Unknown type \"" + type + "\"" );
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()); } }
public static String toString(final double[][] 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(", "); } } /**
/** * Copies element of this type-specific list into the given big array using * optimized system calls. * * @param from * the start index (inclusive). * @param a * the destination big 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 long from, final double[][] a, final long offset, final long length) { DoubleBigArrays.copy(this.a, from, a, offset, length); } /**
/** * 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); } /**
/** * {@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 double a[][], long offset, long length) { ensureIndex(index); DoubleBigArrays.ensureOffsetLength(a, offset, length); while (length-- != 0) add(index++, DoubleBigArrays.get(a, offset++)); } /**
/** * Sets the length of the given big array. * * <p> * <strong>Warning:</strong> the returned array might use part of the segments * of the original array, which must be considered read-only after calling this * method. * * @param array * a big array. * @param length * the new length for the big array. * @return {@code array}, if it contains exactly {@code length} entries; * otherwise, if it contains <em>more</em> than {@code length} entries, * a big array with {@code length} entries whose entries are the same as * the first {@code length} entries of {@code array}; otherwise, a big * array with {@code length} entries whose first {@code length(array)} * entries are the same as those of {@code array}. * */ public static double[][] setLength(final double[][] array, final long length) { final long oldLength = length(array); if (length == oldLength) return array; if (length < oldLength) return trim(array, length); return ensureCapacity(array, length); } /**
/** * 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 double a[][], final long offset, final long length) { ensureIndex(index); DoubleBigArrays.ensureOffsetLength(a, offset, length); grow(size + length); DoubleBigArrays.copy(this.a, index, this.a, index + length, size - index); DoubleBigArrays.copy(a, offset, this.a, index, length); size += length; } @Override
/** * {@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 double a[][], long offset, long length) { DoubleBigListIterator i = listIterator(from); DoubleBigArrays.ensureOffsetLength(a, offset, length); if (from + length > size64()) throw new IndexOutOfBoundsException( "End index (" + (from + length) + ") is greater than list size (" + size64() + ")"); while (length-- != 0) DoubleBigArrays.set(a, offset++, i.nextDouble()); } /**