it.unimi.dsi.fastutil.longs.LongArrays Java Examples

The following examples show how to use it.unimi.dsi.fastutil.longs.LongArrays. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill( final long from, final long to, final boolean value ) {
	if ( to / Long.SIZE == from / Long.SIZE ) {
		if ( value ) bits[ (int)( from / Long.SIZE ) ] |= ( 1L << to - from ) - 1 << from; 
		else bits[ (int)( from / Long.SIZE ) ] &= ~( ( 1L << to - from ) - 1 << from );
		return;
	}
	LongArrays.fill( bits, (int)( ( from + Long.SIZE - 1 ) / Long.SIZE ), (int)( to / Long.SIZE ), value ? -1L : 0L );
	if ( from % Long.SIZE != 0 ) {
		if ( value ) bits[ (int)( from / Long.SIZE ) ] |= -1L << from % Long.SIZE;
		else bits[ (int)( from / Long.SIZE ) ] &= ( 1L << from % Long.SIZE ) - 1;
	}

	if ( to % Long.SIZE != 0 ) {
		if ( value ) bits[ (int)( to / Long.SIZE ) ] |= ( 1L << to % Long.SIZE ) - 1;
		else bits[ (int)( to / Long.SIZE ) ] &= -1L << to % Long.SIZE;
	}
}
 
Example #2
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public LongArrayBitVector length( final long newLength ) {
	bits = LongArrays.ensureCapacity( bits, numWords( newLength ), numWords( length ) );
	final long oldLength = length;
	if ( newLength < oldLength ) fill( newLength, oldLength, false );
	length = newLength;
	return this;
}
 
Example #3
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void fill( final boolean value ) {
	final int fullWords = (int)( length / Long.SIZE );
	LongArrays.fill( bits, 0, fullWords, value ? 0xFFFFFFFFFFFFFFFFL : 0L );
	if ( length % Long.SIZE != 0 ) {
		if ( value ) bits[ fullWords ] = ( 1L << length % Long.SIZE ) - 1;
		else bits[ fullWords ] = 0;
	}
}
 
Example #4
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/** Reduces as must as possible the size of the backing array.
 * 
 * @return true if some trimming was actually necessary.
 */

public boolean trim() {
	if ( bits.length == numWords( length ) ) return false;
	bits = LongArrays.setLength( bits, numWords( length ) );
	return true;
}
 
Example #5
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public LongArrayBitVector replace( final LongArrayBitVector bv ) {
	ensureCapacity( bv.length );
	final long[] bits = this.bits;
	final long[] bvBits = bv.bits;
	final int bvFirstFreeWord = word( bv.length - 1 ) + 1;
	for( int i = bvFirstFreeWord; i-- != 0; ) bits[ i ] = bvBits[ i ];
	final int thisFirstFreeWord = word( length - 1 ) + 1;
	if ( bvFirstFreeWord < thisFirstFreeWord ) LongArrays.fill( this.bits, bvFirstFreeWord, thisFirstFreeWord, 0 );
	this.length = bv.length;
	return this;
}
 
Example #6
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LongArrayBitVector replace( final BitVector bv ) {
	final long bvLength = bv.length();
	ensureCapacity( bvLength );
	final long[] bits = this.bits;
	final long fullBits = bvLength - bvLength % Long.SIZE;
	for( long i = 0; i < fullBits; i += Long.SIZE ) bits[ (int)( i / Long.SIZE ) ] = bv.getLong( i, i + Long.SIZE );
	final int bvFirstFreeWord = word( bvLength - 1 ) + 1;
	final int thisFirstFreeWord = word( length - 1 ) + 1; 
	if ( bvLength % Long.SIZE != 0 ) bits[ (int)( fullBits / Long.SIZE ) ] = bv.getLong( fullBits, bvLength );
	if ( bvFirstFreeWord < thisFirstFreeWord ) LongArrays.fill( this.bits, bvFirstFreeWord, thisFirstFreeWord, 0 );
	this.length = bvLength;
	return this;
}
 
Example #7
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected LongArrayBitVector( final long capacity ) {
	this.bits = capacity > 0 ? new long[ numWords( capacity ) ] : LongArrays.EMPTY_ARRAY;
}
 
Example #8
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/** Sets the size of this bit vector to 0.
 * <P>Note that this method does not try to reallocate that backing array.
 * If you want to force that behaviour, call {@link #trim()} afterwards.
 */
public void clear() {
	LongArrays.fill( bits, 0, word( length - 1 ) + 1, 0 );
	length = 0;
}
 
Example #9
Source File: BloomFilter.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/** Clears this filter.
 */

public void clear() {
	LongArrays.fill( bits, 0 );
	size = 0;
}
 
Example #10
Source File: LongArrayBitVector.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/** Ensures that this bit vector can hold the specified number of bits.
 * 
 * <p>This method uses {@link LongArrays#grow(long[], int, int)} to
 * ensure that there is enough space for the given number of bits. As a
 * consequence, the actual length of the long array allocated might be
 * larger than expected.
 * 
 * @param numBits the number of bits that this vector must be able to contain. 
 * @return this bit vector.
 */

public LongArrayBitVector ensureCapacity( final long numBits ) {
	bits = LongArrays.grow( bits, numWords( numBits ), numWords( length ) );
	return this;
}