/** * 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 int a[][], int length, long pos) { IntBigArrays.set(a, pos, length); return 1; } /**
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = IntBigArrays.newBigArray(size); for (int i = 0; i < size; i++) IntBigArrays.set(a, i, s.readInt()); } }
@Override public int set(final long index, final int k) { if (index >= size) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")"); int old = IntBigArrays.get(a, index); IntBigArrays.set(a, index, k); return old; } @Override
/** * 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 int[][] shuffle(final int[][] 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 int t = get(a, from + i); set(a, from + i, get(a, from + p)); set(a, from + p, t); } return a; } /**
@Override public boolean add(final int k) { grow(size + 1); IntBigArrays.set(a, size++, k); assert size <= IntBigArrays.length(a); return true; } @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 int[][] shuffle(final int[][] a, final Random random) { for (long i = length(a); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final int t = get(a, i); set(a, i, get(a, p)); set(a, p, t); } return a; } }
protected int combineSizes( final OutputBitStream sizesOutputBitStream ) throws IOException { int maxDocSize = 0, currDoc = 0; if ( needsSizes ) size = IntBigArrays.newBigArray( numberOfDocuments ); for( int i = 0; i < numIndices; i++ ) { final IntIterator sizes = sizes( i ); int s = 0; long j = index[ i ].numberOfDocuments; while( j-- != 0 ) { maxDocSize = Math.max( maxDocSize, s = sizes.nextInt() ); if ( needsSizes ) IntBigArrays.set( size, currDoc++, s ); sizesOutputBitStream.writeGamma( s ); } if ( sizes instanceof Closeable ) ((Closeable)sizes).close(); } return maxDocSize; }
/** * 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 int[][] key = this.key; for (;;) { pos = ((last = pos) + 1) & mask; for (;;) { if (((IntBigArrays.get(key, pos)) == (0))) { IntBigArrays.set(key, last, (0)); return; } slot = (it.unimi.dsi.fastutil.HashCommon.mix((long) ((IntBigArrays.get(key, pos))))) & mask; if (last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos) break; pos = (pos + 1) & mask; } IntBigArrays.set(key, last, IntBigArrays.get(key, pos)); } } private boolean removeEntry(final int base, final int displ) {
protected int combineSizes( final OutputBitStream sizesOutputBitStream ) throws IOException { int maxDocSize = 0, currDoc = 0; if ( needsSizes ) size = IntBigArrays.newBigArray( numberOfDocuments ); for( int i = 0; i < numIndices; i++ ) { final IntIterator sizes = sizes( i ); int s = 0; long j = index[ i ].numberOfDocuments; while( j-- != 0 ) { maxDocSize = Math.max( maxDocSize, s = sizes.nextInt() ); if ( needsSizes ) IntBigArrays.set( size, currDoc++, s ); sizesOutputBitStream.writeGamma( s ); } if ( sizes instanceof Closeable ) ((Closeable)sizes).close(); } return maxDocSize; }
private static void selectionSort(final int[][] a, final int[][] 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 (((IntBigArrays.get(a, j)) < (IntBigArrays.get(a, m))) || ((IntBigArrays.get(a, j)) == (IntBigArrays.get(a, m))) && ((IntBigArrays.get(b, j)) < (IntBigArrays.get(b, m)))) m = j; if (m != i) { int t = IntBigArrays.get(a, i); IntBigArrays.set(a, i, IntBigArrays.get(a, m)); IntBigArrays.set(a, m, t); t = IntBigArrays.get(b, i); IntBigArrays.set(b, i, IntBigArrays.get(b, m)); IntBigArrays.set(b, m, t); } } } /**
protected int combineSizes( final OutputBitStream sizesOutputBitStream ) throws IOException { int curSize, s, maxDocSize = 0; if ( needsSizes ) size = IntBigArrays.newBigArray( numberOfDocuments ); final IntIterator[] sizes = new IntIterator[ numIndices ]; for( int i = 0; i < numIndices; i++ ) sizes[ i ] = sizes( i ); for( int d = 0; d < numberOfDocuments; d++ ) { curSize = 0; for( int i = 0; i < numIndices; i++ ) { if ( d < index[ i ].numberOfDocuments && ( s = sizes[ i ].nextInt() ) != 0 ) { if ( curSize != 0 ) throw new IllegalArgumentException( "Document " + d + " has nonzero length in two indices" ); curSize = s; } } if ( needsSizes ) IntBigArrays.set( size, d, curSize ); if ( curSize > maxDocSize ) maxDocSize = curSize; sizesOutputBitStream.writeGamma( curSize ); } for( int i = 0; i < numIndices; i++ ) if ( sizes[ i ] instanceof Closeable ) ((Closeable)sizes[ i ]).close(); return maxDocSize; }
protected int combineSizes( final OutputBitStream sizesOutputBitStream ) throws IOException { int curSize, s, maxDocSize = 0; if ( needsSizes ) size = IntBigArrays.newBigArray( numberOfDocuments ); final IntIterator[] sizes = new IntIterator[ numIndices ]; for( int i = 0; i < numIndices; i++ ) sizes[ i ] = sizes( i ); for( int d = 0; d < numberOfDocuments; d++ ) { curSize = 0; for( int i = 0; i < numIndices; i++ ) { if ( d < index[ i ].numberOfDocuments && ( s = sizes[ i ].nextInt() ) != 0 ) { if ( curSize != 0 ) throw new IllegalArgumentException( "Document " + d + " has nonzero length in two indices" ); curSize = s; } } if ( needsSizes ) IntBigArrays.set( size, d, curSize ); if ( curSize > maxDocSize ) maxDocSize = curSize; sizesOutputBitStream.writeGamma( curSize ); } for( int i = 0; i < numIndices; i++ ) if ( sizes[ i ] instanceof Closeable ) ((Closeable)sizes[ i ]).close(); return maxDocSize; }
@Override public void add(final long index, final int k) { ensureIndex(index); grow(size + 1); if (index != size) IntBigArrays.copy(a, index, a, index + 1, size - index); IntBigArrays.set(a, index, k); size++; assert size <= IntBigArrays.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 int a[][], long offset, long length) { IntBigListIterator i = listIterator(from); IntBigArrays.ensureOffsetLength(a, offset, length); if (from + length > size64()) throw new IndexOutOfBoundsException( "End index (" + (from + length) + ") is greater than list size (" + size64() + ")"); while (length-- != 0) IntBigArrays.set(a, offset++, i.nextInt()); } /**
if ( indexingIsVirtual ) IntBigArrays.set( currSize, documentPointer, IntBigArrays.get( currSize, documentPointer ) + occsInCurrDoc + virtualDocumentGap );
if ( indexingIsVirtual ) IntBigArrays.set( currSize, documentPointer, IntBigArrays.get( currSize, documentPointer ) + occsInCurrDoc + virtualDocumentGap );