/** * Writes a length. * * @param a * the data array. * @param length * the length to be written. * @param pos * the starting position. * @return the number of elements coding {@code length}. */ private static int writeInt(final long a[][], int length, long pos) { LongBigArrays.set(a, pos, length); return 1; } /**
@Override public long set(final long index, final long k) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); long old = LongBigArrays.get(a, index); LongBigArrays.set(a, index, k); return old; } @Override
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = LongBigArrays.newBigArray(size); for (int i = 0; i < size; i++) LongBigArrays.set(a, i, s.readLong()); } }
/** Computes the inverse of a permutation expressed * as a {@linkplain BigArrays big array} of <var>n</var> distinct long integers in [0 .. <var>n</var>). * * <p><strong>Warning</strong>: if <code>perm</code> is not a permutation, * essentially anything can happen. * * @param perm the permutation to be inverted. * @param inv the big array storing the inverse. * @return <code>inv</code>. */ public static long[][] invertPermutation(long[][] perm, long[][] inv) { for(int i = perm.length; i-- != 0;) { final long t[] = perm[i]; for(int d = t.length; d-- != 0;) LongBigArrays.set(inv, t[d], BigArrays.index(i, d)); } return inv; }
/** * 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 long[][] shuffle(final long[][] 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 long t = get(a, from + i); set(a, from + i, get(a, from + p)); set(a, from + p, t); } return a; } /**
/** * 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 long[][] shuffle(final long[][] a, final Random random) { for (long i = length(a); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final long t = get(a, i); set(a, i, get(a, p)); set(a, p, t); } return a; } }
/** Computes in place the inverse of a permutation expressed * as a {@linkplain BigArrays big array} of <var>n</var> distinct long integers in [0 .. <var>n</var>). * * <p><strong>Warning</strong>: if <code>perm</code> is not a permutation, * essentially anything can happen. * * @param perm the permutation to be inverted. * @return <code>perm</code>. */ public static long[][] invertPermutationInPlace(long[][] perm) { for(long n = LongBigArrays.length(perm); n-- != 0;) { long i = LongBigArrays.get(perm, n); if (i < 0) LongBigArrays.set(perm, n, -i - 1); else if (i != n) { long j, k = n; for(;;) { j = LongBigArrays.get(perm, i); LongBigArrays.set(perm, i, -k - 1); if (j == n) { LongBigArrays.set(perm, n, i); break; } k = i; i = j; } } } return perm; }
@Override public boolean add(final long k) { grow(size + 1); LongBigArrays.set(a, size++, k); assert size <= LongBigArrays.length(a); return true; } @Override
/** Utility method to load a compressed offset file into a list. * * @param in the input bit stream providing the offsets (see {@link BitStreamIndexWriter}). * @param T the number of terms indexed. * @return a list of longs backed by an array; the list has * an additional final element of index <code>T</code> that gives the number * of bytes of the index file. */ public static LongBigList readOffsets( final InputBitStream in, final long T ) throws IOException { final long[][] offset = LongBigArrays.newBigArray( T + 1 ); LOGGER.debug( "Loading offsets..." ); long prev; LongBigArrays.set( offset, 0, prev = in.readLongGamma() ); for( int i = 0; i < T; i++ ) LongBigArrays.set( offset, i + 1, prev = in.readLongGamma() + prev ); LOGGER.debug( "Completed." ); return LongBigArrayBigList.wrap( offset ); }
/** Utility method to load a compressed offset file into a list. * * @param in the input bit stream providing the offsets (see {@link BitStreamIndexWriter}). * @param T the number of terms indexed. * @return a list of longs backed by an array; the list has * an additional final element of index <code>T</code> that gives the number * of bytes of the index file. */ public static LongBigList readOffsets( final InputBitStream in, final long T ) throws IOException { final long[][] offset = LongBigArrays.newBigArray( T + 1 ); LOGGER.debug( "Loading offsets..." ); long prev; LongBigArrays.set( offset, 0, prev = in.readLongGamma() ); for( int i = 0; i < T; i++ ) LongBigArrays.set( offset, i + 1, prev = in.readLongGamma() + prev ); LOGGER.debug( "Completed." ); return LongBigArrayBigList.wrap( offset ); }
/** Utility method to load a compressed offset file into a list. * * @param filename the file containing the offsets (see {@link BitStreamIndexWriter}). * @param T the number of terms indexed. * @return a list of longs backed by an array; the list has * an additional final element of index <code>T</code> that gives the number * of bytes of the index file. */ public static LongBigList readOffsets( final CharSequence filename, final long T ) throws IOException { final InputBitStream in = new InputBitStream( filename.toString() ); final long[][] offset = LongBigArrays.newBigArray( T + 1 ); LOGGER.debug( "Loading offsets..." ); long prev; LongBigArrays.set( offset, 0, prev = in.readLongGamma() ); for( int i = 0; i < T; i++ ) LongBigArrays.set( offset, i + 1, prev = in.readLongGamma() + prev ); in.close(); LOGGER.debug( "Completed." ); return LongBigArrayBigList.wrap( offset ); }
/** * Shifts left entries with the specified hash code, starting at the specified * position, and empties the resulting free entry. * * @param pos * a starting position. */ protected final void shiftKeys(long pos) { // Shift entries with the same hash. long last, slot; final long[][] key = this.key; for (;;) { pos = ((last = pos) + 1) & mask; for (;;) { if (((LongBigArrays.get(key, pos)) == (0))) { LongBigArrays.set(key, last, (0)); return; } slot = it.unimi.dsi.fastutil.HashCommon.mix((LongBigArrays.get(key, pos))) & mask; if (last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos) break; pos = (pos + 1) & mask; } LongBigArrays.set(key, last, LongBigArrays.get(key, pos)); } } private boolean removeEntry(final int base, final int displ) {
private static void selectionSort(final long[][] a, final long[][] 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 (((LongBigArrays.get(a, j)) < (LongBigArrays.get(a, m))) || ((LongBigArrays.get(a, j)) == (LongBigArrays.get(a, m))) && ((LongBigArrays.get(b, j)) < (LongBigArrays.get(b, m)))) m = j; if (m != i) { long t = LongBigArrays.get(a, i); LongBigArrays.set(a, i, LongBigArrays.get(a, m)); LongBigArrays.set(a, m, t); t = LongBigArrays.get(b, i); LongBigArrays.set(b, i, LongBigArrays.get(b, m)); LongBigArrays.set(b, m, t); } } } /**
@Override public void add(final long index, final long k) { ensureIndex(index); grow(size + 1); if (index != size) LongBigArrays.copy(a, index, a, index + 1, size - index); LongBigArrays.set(a, index, k); size++; assert size <= LongBigArrays.length(a); } @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 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()); } /**
/** Generates a 64-bit signatures big array using a given function and string sequence. * * <p>The resulting big array can be saved using {@link BinIO#storeLongs(long[][], CharSequence)} * or similar {@link BinIO} methods. * * @param iterator an iterator over a list of strings. * @param function the function to be signed. * @param pl a progress logger, or {@code null}. * @return a big array of 64-bit signatures. */ public static long[][] sign(final Iterator<? extends CharSequence> iterator, final Object2LongFunction<? extends CharSequence> function , final ProgressLogger pl) { final long n = function instanceof Size64 ? ((Size64)function).size64() : function .size(); final long[][] signature = LongBigArrays.newBigArray(n); if (pl != null) { pl.expectedUpdates = n; pl.start("Signing..."); } CharSequence s; for(long i = 0; i < n; i++) { s = iterator.next(); LongBigArrays.set(signature, function .getLong(s), signature(s)); if (pl != null) pl.lightUpdate(); } if (iterator.hasNext()) throw new IllegalStateException("Iterator provides more than " + n + " elements"); if (pl != null) pl.done(); return signature; }
final int zz = c; t = LongBigArrays.get(a, d + first); LongBigArrays.set(a, d + first, z); z = u; u = LongBigArrays.get(b, d + first); LongBigArrays.set(b, d + first, z); c = ByteBigArrays.get(digit, d) & 0xFF; ByteBigArrays.set(digit, d, (byte) zz); LongBigArrays.set(a, i + first, t); LongBigArrays.set(b, i + first, u);