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 getDouble(final long index) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); return DoubleBigArrays.get(a, index); } @Override
@Override public long lastIndexOf(final double k) { for (long i = size; i-- != 0;) if ((Double.doubleToLongBits(k) == Double.doubleToLongBits(DoubleBigArrays.get(a, i)))) return i; return -1; } @Override
@Override public long indexOf(final double k) { for (long i = 0; i < size; i++) if ((Double.doubleToLongBits(k) == Double.doubleToLongBits(DoubleBigArrays.get(a, i)))) return i; return -1; } @Override
private static long med3(final double x[][], final long a, final long b, final long c, DoubleComparator comp) { int ab = comp.compare(get(x, a), get(x, b)); int ac = comp.compare(get(x, a), get(x, c)); int bc = comp.compare(get(x, b), get(x, c)); return (ab < 0 ? (bc < 0 ? b : ac < 0 ? c : a) : (bc > 0 ? b : ac > 0 ? c : a)); } private static void selectionSort(final double[][] a, final long from, final long to, final DoubleComparator comp) {
private static void selectionSort(final double[][] a, final double[][] b, final long from, final long to) { for (long i = from; i < to - 1; i++) { long m = i; for (long j = i + 1; j < to; j++) if ((Double.compare((DoubleBigArrays.get(a, j)), (DoubleBigArrays.get(a, m))) < 0) || (Double.compare((DoubleBigArrays.get(a, j)), (DoubleBigArrays.get(a, m))) == 0) && (Double.compare((DoubleBigArrays.get(b, j)), (DoubleBigArrays.get(b, m))) < 0)) m = j; if (m != i) { double t = DoubleBigArrays.get(a, i); DoubleBigArrays.set(a, i, DoubleBigArrays.get(a, m)); DoubleBigArrays.set(a, m, t); t = DoubleBigArrays.get(b, i); DoubleBigArrays.set(b, i, DoubleBigArrays.get(b, m)); DoubleBigArrays.set(b, m, t); } } } /**
@Override public double previousDouble() { if (!hasPrevious()) throw new NoSuchElementException(); return DoubleBigArrays.get(a, last = --pos); } @Override
private static void selectionSort(final double[][] a, final long from, final long to, final DoubleComparator comp) { for (long i = from; i < to - 1; i++) { long m = i; for (long j = i + 1; j < to; j++) if (comp.compare(DoubleBigArrays.get(a, j), DoubleBigArrays.get(a, m)) < 0) m = j; if (m != i) swap(a, i, m); } } /**
@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
@Override public double nextDouble() { if (!hasNext()) throw new NoSuchElementException(); return DoubleBigArrays.get(a, last = pos++); } @Override
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); for (int i = 0; i < size; i++) s.writeDouble(DoubleBigArrays.get(a, i)); }
public double score() { return DoubleBigArrays.get( score, documentIterator.document() ); }
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(", "); } } /**
public double score() { return DoubleBigArrays.get( score, documentIterator.document() ); }
/** * Shuffles the specified big array fragment using the specified pseudorandom * number generator. * * @param a * the big array to be shuffled. * @param from * the index of the first element (inclusive) to be shuffled. * @param to * the index of the last element (exclusive) to be shuffled. * @param random * a pseudorandom number generator. * @return {@code a}. */ public static double[][] shuffle(final double[][] a, final long from, final long to, final Random random) { for (long i = to - from; i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final double t = get(a, from + i); set(a, from + i, get(a, from + p)); set(a, from + p, t); } return a; } /**
/** * Compares this big list to another big list. * * <p> * This method exists only for sake of efficiency. The implementation inherited * from the abstract implementation would already work. * * @param l * a big list. * @return a negative integer, zero, or a positive integer as this big list is * lexicographically less than, equal to, or greater than the argument. */ public int compareTo(final DoubleBigArrayBigList l) { final long s1 = size64(), s2 = l.size64(); final double a1[][] = a, a2[][] = l.a; double e1, e2; int r, i; for (i = 0; i < s1 && i < s2; i++) { e1 = DoubleBigArrays.get(a1, i); e2 = DoubleBigArrays.get(a2, i); if ((r = (Double.compare((e1), (e2)))) != 0) return r; } return i < s2 ? -1 : (i < s1 ? 1 : 0); } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
@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
/** * 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; } }
/** * {@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++)); } /**