it.unimi.dsi.bits.LongArrayBitVector Java Examples
The following examples show how to use
it.unimi.dsi.bits.LongArrayBitVector.
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: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 6 votes |
public void testCopyAnotherVector() { Random r = new Random( 1 ); LongArrayBitVector bv = LongArrayBitVector.getInstance( 200 ); for( int i = 0; i < 100; i++ ) bv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bv ), bv ); bv = LongArrayBitVector.getInstance( 256 ); for( int i = 0; i < 256; i++ ) bv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bv ), bv ); bv = LongArrayBitVector.getInstance( 10 ); for( int i = 0; i < 10; i++ ) bv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bv ), bv ); BooleanListBitVector bbv = BooleanListBitVector.getInstance( 200 ); for( int i = 0; i < 100; i++ ) bbv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bbv ), bbv ); bbv = BooleanListBitVector.getInstance( 256 ); for( int i = 0; i < 256; i++ ) bbv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bbv ), bbv ); bbv = BooleanListBitVector.getInstance( 10 ); for( int i = 0; i < 10; i++ ) bbv.add( r.nextBoolean() ); assertEquals( LongArrayBitVector.copy( bbv ), bbv ); }
Example #2
Source File: ShiftAddXorSignedStringMap.java From database with GNU General Public License v2.0 | 6 votes |
/** Creates a new shift-add-xor signed string map using a given hash map. * * @param iterator an iterator enumerating a set of strings. * @param map a minimal perfect hash for the strings enumerated by <code>iterator</code>; it must support {@link Function#size() size()} * and have default return value -1. * @param signatureWidth the width, in bits, of the signature of each string. */ public ShiftAddXorSignedStringMap( final Iterator<? extends CharSequence> iterator, final Object2LongFunction<? extends CharSequence> map, final int signatureWidth ) { CharSequence s; this.function = map; this.width = signatureWidth; this.defRetValue = -1; shift = Long.SIZE - width; mask = width == Long.SIZE ? 0 : ( 1L << width ) - 1; final int n = map.size(); signatures = LongArrayBitVector.getInstance().asLongBigList( signatureWidth ).length( n ); for( int i = 0; i < n; i++ ) { s = iterator.next(); signatures.set( map.getLong( s ), signature( s ) ); } if ( iterator.hasNext() ) throw new IllegalStateException( "Iterator provides more than " + n + " elements" ); }
Example #3
Source File: IntBloomFilter.java From database with GNU General Public License v2.0 | 6 votes |
/** Creates a new Bloom filter with given number of hash functions and expected number of elements. * * @param n the expected number of elements. * @param d the number of hash functions; if the filter add not more than <code>n</code> elements, * false positives will happen with probability 2<sup>-<var>d</var></sup>. */ public IntBloomFilter( final int n, final int d ) { this.d = d; bits = LongArrayBitVector.getInstance().length( (long)Math.ceil( ( n * d / NATURAL_LOG_OF_2 ) ) ); m = bits.length() * Long.SIZE; if ( DEBUG ) System.err.println( "Number of bits: " + m ); // The purpose of Random().nextInt() is to generate a different seed at each invocation. final MersenneTwister mersenneTwister = new MersenneTwister( new Random().nextInt() ); a = new int[ d ]; b = new int[ d ]; for( int i = 0; i < d; i++ ) { a[ i ] = mersenneTwister.nextInt(); b[ i ] = mersenneTwister.nextInt(); } }
Example #4
Source File: ImmutableBinaryTrie.java From database with GNU General Public License v2.0 | 6 votes |
/** Creates a trie from a set of elements. * * @param elements a set of elements * @param transformationStrategy a transformation strategy that must turn <code>elements</code> into a list of * distinct, lexicographically increasing (in iteration order) binary words. */ public ImmutableBinaryTrie( final Iterable<? extends T> elements, final TransformationStrategy<? super T> transformationStrategy ) { this.transformationStrategy = transformationStrategy; defRetValue = -1; // Check order final Iterator<? extends T> iterator = elements.iterator(); final ObjectList<LongArrayBitVector> words = new ObjectArrayList<LongArrayBitVector>(); int cmp; if ( iterator.hasNext() ) { final LongArrayBitVector prev = LongArrayBitVector.copy( transformationStrategy.toBitVector( iterator.next() ) ); words.add( prev.copy() ); BitVector curr; while( iterator.hasNext() ) { curr = transformationStrategy.toBitVector( iterator.next() ); cmp = prev.compareTo( curr ); if ( cmp == 0 ) throw new IllegalArgumentException( "The trie elements are not unique" ); if ( cmp > 0 ) throw new IllegalArgumentException( "The trie elements are not sorted" ); prev.replace( curr ); words.add( prev.copy() ); } } root = buildTrie( words, 0 ); }
Example #5
Source File: ImmutableBinaryTrie.java From database with GNU General Public License v2.0 | 6 votes |
private void recToString( final Node n, final MutableString printPrefix, final MutableString result, final MutableString path, final int level ) { if ( n == null ) return; //System.err.println( "Called with prefix " + printPrefix ); result.append( printPrefix ).append( '(' ).append( level ).append( ')' ); if ( n.path != null ) { path.append( LongArrayBitVector.wrap( n.path, n.pathLength ) ); result.append( " path:" ).append( LongArrayBitVector.wrap( n.path, n.pathLength ) ); } if ( n.word >= 0 ) result.append( " word: " ).append( n.word ).append( " (" ).append( path ).append( ')' ); result.append( '\n' ); path.append( '0' ); recToString( n.left, printPrefix.append( '\t' ).append( "0 => " ), result, path, level + 1 ); path.charAt( path.length() - 1, '1' ); recToString( n.right, printPrefix.replace( printPrefix.length() - 5, printPrefix.length(), "1 => "), result, path, level + 1 ); path.delete( path.length() - 1, path.length() ); printPrefix.delete( printPrefix.length() - 6, printPrefix.length() ); //System.err.println( "Path now: " + path + " Going to delete from " + ( path.length() - n.pathLength)); path.delete( path.length() - n.pathLength, path.length() ); }
Example #6
Source File: HuTuckerCodecTest.java From database with GNU General Public License v2.0 | 6 votes |
public void testThreeNonequiprobableSymbols() throws IOException { HuTuckerCodec codec = new HuTuckerCodec( new int[] { 1, 2, 4 } ); assertEquals( 3, codec.codeWords().length ); BitVector v = LongArrayBitVector.ofLength( 2 ); assertEquals( v, codec.codeWords()[ 0 ] ); v.set( 1 ); assertEquals( v, codec.codeWords()[ 1 ] ); v = LongArrayBitVector.ofLength( 1 ); v.set( 0 ); assertEquals( v, codec.codeWords()[ 2 ] ); long seed = System.currentTimeMillis(); System.err.println( seed ); Random r = new Random( seed ); checkPrefixCodec( codec, r ); }
Example #7
Source File: PrefixFreeTransformationStrategyTest.java From database with GNU General Public License v2.0 | 6 votes |
public void testGetLong() { LongArrayBitVector v = LongArrayBitVector.getInstance(); v.append( 0xFFFFFFFFL, 32 ); TransformationStrategy<BitVector> prefixFree = TransformationStrategies.prefixFree(); BitVector p = prefixFree.toBitVector( v ); assertEquals( 0xFFFFFFFFFFFFFFFFL, p.getLong( 0, 64 ) ); assertFalse( p.getBoolean( 64 ) ); v.clear(); v.append( 0x0, 32 ); assertEquals( 0x5555555555555555L, p.getLong( 0, 64 ) ); assertFalse( p.getBoolean( 64 ) ); v.clear(); v.append( 0x3, 32 ); assertEquals( 0x555555555555555FL, p.getLong( 0, 64 ) ); assertEquals( 0x5FL, p.getLong( 0, 7 ) ); }
Example #8
Source File: ImmutableBinaryTrieTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testImmutableBinaryTrie( List<String> strings ) { ObjectArrayList<BitVector> vectors = new ObjectArrayList<BitVector>(); for( int i = 0; i < strings.size(); i++ ) { BitVector v = LongArrayBitVector.ofLength( strings.get( i ).length() ); for( int j = 0; j < strings.get( i ).length(); j++ ) if ( strings.get( i ).charAt( j ) == '1' ) v.set( j ); vectors.add( v ); } ImmutableBinaryTrie<BitVector> t = new ImmutableBinaryTrie<BitVector>( vectors, TransformationStrategies.identity() ); assertEquals( vectors.size(), t.size() ); for( int i = 0; i < vectors.size(); i++ ) assertEquals( vectors.get( i ).toString(), i, t.getLong( vectors.get( i ) ) ); }
Example #9
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testEquals() { LongArrayBitVector v = LongArrayBitVector.getInstance().length( 100 ); for( int i = 0; i < 50; i++ ) v.set( i * 2 ); LongArrayBitVector w = v.copy(); assertEquals( v, w ); w.length( 101 ); assertFalse( v.equals( w ) ); w.length( 100 ); w.set( 3 ); assertFalse( v.equals( w ) ); }
Example #10
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testLengthClearsBits() { LongArrayBitVector bv = LongArrayBitVector.getInstance().length( 100 ); bv.fill( true ); bv.length( 0 ); bv.append( 0, 1 ); assertFalse( bv.getBoolean( 0 ) ); }
Example #11
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testHashCodeConsistency() { LongArrayBitVector b = LongArrayBitVector.of( 0, 1, 1, 0, 0, 1 ); assertEquals( BooleanListBitVector.getInstance().replace( b ).hashCode(), b.hashCode() ); b = LongArrayBitVector.wrap( new long[]{ 0x234598729872983L, 0x234598729872983L, 0x234598729872983L, 0xFFFF }, 222 ); assertEquals( BooleanListBitVector.getInstance().replace( b ).hashCode(), b.hashCode() ); assertEquals( BitVectors.EMPTY_VECTOR.hashCode(), b.length( 0 ).hashCode() ); }
Example #12
Source File: BitVectorTestCase.java From database with GNU General Public License v2.0 | 5 votes |
public static void testReplace( BitVector b ) { Random r = new Random( 1 ); LongArrayBitVector bv = LongArrayBitVector.getInstance( 200 ); for( int i = 0; i < 100; i++ ) bv.add( r.nextBoolean() ); assertEquals( b.replace( bv ), bv ); bv = LongArrayBitVector.getInstance( 256 ); for( int i = 0; i < 256; i++ ) bv.add( r.nextBoolean() ); assertEquals( b.replace( bv ), bv ); bv = LongArrayBitVector.getInstance( 10 ); for( int i = 0; i < 10; i++ ) bv.add( r.nextBoolean() ); assertEquals( b.replace( bv ), bv ); }
Example #13
Source File: BitVectorTestCase.java From database with GNU General Public License v2.0 | 5 votes |
public static void testAppend( BitVector b ) { b.clear(); LongArrayBitVector v = LongArrayBitVector.ofLength( 200 ); for( int i = 0; i < 60; i++ ) v.set( i * 3 ); b.append( v ); assertEquals( b, v ); b.clear(); b.add( true ); b.append( v ); LongArrayBitVector w = LongArrayBitVector.ofLength( 201 ); for( int i = 0; i < 60; i++ ) w.set( i * 3 + 1 ); w.set( 0 ); assertEquals( w, b ); }
Example #14
Source File: AbstractBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testCompareTo() { MinimalAlternatingBitVector v = new MinimalAlternatingBitVector(); LongArrayBitVector w = LongArrayBitVector.copy( v ); assertEquals( 0, w.compareTo( v ) ); assertEquals( 0, v.compareTo( w ) ); w.set( 100 ); assertEquals( 1, w.compareTo( v ) ); assertEquals( -1, v.compareTo( w ) ); w = LongArrayBitVector.ofLength( 10 ); assertEquals( -1, w.compareTo( v ) ); assertEquals( 1, v.compareTo( w ) ); w = LongArrayBitVector.of( 1 ); assertEquals( 1, w.compareTo( v ) ); assertEquals( -1, v.compareTo( w ) ); }
Example #15
Source File: PrefixFreeTransformationStrategyTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testGetBoolean() { LongArrayBitVector v = LongArrayBitVector.of( 0, 1, 0 ); TransformationStrategy<BitVector> prefixFree = TransformationStrategies.prefixFree(); BitVector p = prefixFree.toBitVector( v ); assertTrue( p.getBoolean( 0 ) ); assertFalse( p.getBoolean( 1 ) ); assertTrue( p.getBoolean( 2 ) ); assertTrue( p.getBoolean( 3 ) ); assertTrue( p.getBoolean( 4 ) ); assertFalse( p.getBoolean( 5 ) ); assertFalse( p.getBoolean( 6 ) ); assertEquals( LongArrayBitVector.of( 1, 0, 1, 1, 1, 0, 0 ), p ); }
Example #16
Source File: BitVectorsTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testMakeOffline() throws IOException { final BitVector[] a = new BitVector[] { BitVectors.ZERO, BitVectors.ONE, BitVectors.EMPTY_VECTOR, LongArrayBitVector.wrap( new long[] { 0xAAAAAAAAAAAAAAAAL }, 64 ), LongArrayBitVector.wrap( new long[] { 0xAAAAAAAAAAAAAAAL }, 60 ), LongArrayBitVector.wrap( new long[] { 0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAAAAAAAAAAL }, 128 ), LongArrayBitVector.wrap( new long[] { 0xAAAAAAAAAAAAAAAAL, 0xAAAAAAAAAAAAAAAL }, 124 ) }; OfflineIterable<BitVector,LongArrayBitVector> iterable = new OfflineIterable<BitVector, LongArrayBitVector>( BitVectors.OFFLINE_SERIALIZER, LongArrayBitVector.getInstance() ); iterable.addAll( Arrays.asList( a ) ); Iterator<LongArrayBitVector> iterator = iterable.iterator(); for( int i = 0; i < a.length; i++ ) assertEquals( a[ i ], iterator.next() ); assertFalse( iterator.hasNext() ); }
Example #17
Source File: HuffmanCodecTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testThreeNonequiprobableSymbols() throws IOException { HuffmanCodec codec = new HuffmanCodec( new int[] { 1, 2, 4 } ); assertEquals( 3, codec.codeWords().length ); BitVector v = LongArrayBitVector.ofLength( 2 ); v.set( 0 ); assertEquals( v, codec.codeWords()[ 1 ] ); v.set( 1 ); assertEquals( v, codec.codeWords()[ 0 ] ); assertEquals( LongArrayBitVector.ofLength( 1 ), codec.codeWords()[ 2 ] ); long seed = System.currentTimeMillis(); System.err.println( seed ); Random r = new Random( seed ); checkPrefixCodec( codec, r ); }
Example #18
Source File: HuTuckerCodecTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testOneSymbol() throws IOException { HuTuckerCodec codec = new HuTuckerCodec( new int[] { 1 } ); assertEquals( 1, codec.codeWords().length ); assertEquals( LongArrayBitVector.ofLength( 0 ), codec.codeWords()[ 0 ] ); long seed = System.currentTimeMillis(); System.err.println( seed ); Random r = new Random( seed ); checkPrefixCodec( codec, r ); }
Example #19
Source File: HuTuckerCodecTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testTwoEquiprobableSymbols() throws IOException { HuTuckerCodec codec = new HuTuckerCodec( new int[] { 1, 1 } ); assertEquals( 2, codec.codeWords().length ); assertEquals( LongArrayBitVector.ofLength( 1 ), codec.codeWords()[ 0 ] ); BitVector v = LongArrayBitVector.ofLength( 1 ); v.set( 0 ); assertEquals( v, codec.codeWords()[ 1 ] ); long seed = System.currentTimeMillis(); System.err.println( seed ); Random r = new Random( seed ); checkPrefixCodec( codec, r ); }
Example #20
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testRemove() { BitVectorTestCase.testRemove( LongArrayBitVector.getInstance() ); LongArrayBitVector v = LongArrayBitVector.getInstance(); v.clear(); v.size( 65 ); v.set( 64 ); v.removeBoolean( 0 ); assertEquals( 0, v.bits()[ 1 ] ); v.clear(); }
Example #21
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testFillFlip() { LongArrayBitVector v = LongArrayBitVector.getInstance(); v.size( 100 ); BitVectorTestCase.testFillFlip( v ); BitVectorTestCase.testFillFlip( v.subVector( 0, 90 ) ); BitVectorTestCase.testFillFlip( v.subVector( 5, 90 ) ); }
Example #22
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 5 votes |
public void testSetClearFlip() { LongArrayBitVector v = LongArrayBitVector.getInstance(); v.size( 1 ); BitVectorTestCase.testSetClearFlip( v ); v.size( 64 ); BitVectorTestCase.testSetClearFlip( v ); v.size( 80 ); BitVectorTestCase.testSetClearFlip( v ); v.size( 150 ); BitVectorTestCase.testSetClearFlip( v ); BitVectorTestCase.testSetClearFlip( v.subVector( 0, 90 ) ); BitVectorTestCase.testSetClearFlip( v.subVector( 5, 90 ) ); }
Example #23
Source File: TableWriter.java From mph-table with Apache License 2.0 | 5 votes |
private static <K, V> Select sizesToSelect(final TableConfig<K, V> config, final File tempSizes, final long dataSize) throws IOException { final long numEntries = tempSizes.length() / 4; try (final MMapBuffer sizes = new MMapBuffer(tempSizes, 0L, numEntries * 4, FileChannel.MapMode.READ_ONLY, ByteOrder.nativeOrder())) { final DirectMemory sizesMemory = sizes.memory(); final long maxValue = config.compressOffset(dataSize, numEntries); final BitVector bits = LongArrayBitVector.ofLength(maxValue); for (long i = 0, offset = 0; i < numEntries; offset += sizesMemory.getInt(i * 4), ++i) { final long value = config.compressOffset(offset, i); bits.set(value); } return new HintedBsearchSelect(new Rank9(bits)); } }
Example #24
Source File: CanonicalHuffmanRabaCoder.java From database with GNU General Public License v2.0 | 4 votes |
/** * Reconstruct the {@link DecoderInputs} from the data written by * {@link #writeDecoderInputs(BitVector[], OutputBitStream)}. * * @param nsymbols * The #of symbols. * @param ibs * The input bit stream. * @param sb * Debugging information is added to this buffer (optional). * * @return The decoded bit lengths and the corresponding symbol indices for * the canonical huffman code. * * @throws IOException */ static protected DecoderInputs readDecoderInputs(final int nsymbols, final InputBitStream ibs, final StringBuilder sb) throws IOException { final int min = ibs.readNibble(); final int max = ibs.readNibble(); if (sb != null) sb.append("min=" + min + ", max=" + max+"\n"); final int[] length = new int[nsymbols]; final int[] symbol = new int[nsymbols]; // the current code length int codeSize = min; int lastSymbol = 0; while (codeSize <= max) { final int sizeCount = ibs.readNibble(); if (sb != null) sb.append("codeSize="+codeSize+", sizeCount="+sizeCount+", symbols=["); for (int i = 0; i < sizeCount; i++, lastSymbol++) { final int tmp = ibs.readNibble(); if (sb != null) sb.append(" "+tmp); length[lastSymbol] = codeSize; symbol[lastSymbol] = tmp; } if (sb != null) sb.append(" ]\n"); codeSize++; } final int shortestCodeWordLength = length[0]; final BitVector shortestCodeWord = LongArrayBitVector.getInstance() .length(shortestCodeWordLength); for (int i = shortestCodeWordLength-1; i >= 0; i--) { shortestCodeWord.set(i, ibs.readBit()); } if (sb != null) { sb.append("shortestCodeWord=" + shortestCodeWord+"\n"); } return new DecoderInputs(shortestCodeWord, length, symbol); }
Example #25
Source File: BitVectorTestCase.java From database with GNU General Public License v2.0 | 4 votes |
public static void its( BitVector b ) { for( int i = 0; i < 100; i++ ) b.add( i % 2 ); assertTrue( LongArrayBitVector.wrap( b.bits(), b.length() ).toString(), Arrays.equals( new long[] { 0xAAAAAAAAAAAAAAAAL, 0x0000000AAAAAAAAAL }, b.bits() ) ); }
Example #26
Source File: BitVectorTestCase.java From database with GNU General Public License v2.0 | 4 votes |
public static void testCopy( final BitVector v ) { v.clear(); v.size( 100 ); v.fill( 5, 80, true ); BitVector w = v.copy( 0, 85 ); assertEquals( w, v.subVector( 0, 85 ).copy() ); for( int i = w.size(); i-- != 0; ) assertEquals( i >= 5 && i < 80, w.getBoolean( i ) ); w = v.copy( 5, 85 ); assertEquals( w, v.subVector( 5, 85 ).copy() ); for( int i = w.size(); i-- != 0; ) assertEquals( i < 75, w.getBoolean( i ) ); v.clear(); int[] bits = { 0,0,0,0,1,1,1,0,0,0,0,1,1,0,0 }; for( int i = 0; i < bits.length; i++ ) v.add( bits[ i ] ); LongArrayBitVector c = LongArrayBitVector.getInstance(); for( int i = 5; i < bits.length; i++ ) c.add( bits[ i ] ); assertEquals( c, v.copy( 5, 15 ) ); assertEquals( c, v.subVector( 5, 15 ).copy() ); v.clear(); bits = new int[] { 0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0 }; for( int i = 0; i < bits.length; i++ ) v.add( bits[ i ] ); c = LongArrayBitVector.getInstance(); for( int i = 5; i < bits.length - 2; i++ ) c.add( bits[ i ] ); assertEquals( c, v.copy( 5, bits.length - 2 ) ); assertEquals( v, v.copy() ); long[] words = new long[] { 0xDEADBEEFDEADF00DL, 0xDEADBEEFDEADF00DL, 0xDEADBEEFDEADF00DL, }; long[] copyWords16 = new long[] { 0xF00DDEADBEEFDEADL, 0xF00DDEADBEEFDEADL, 0xBEEFDEADL }; long[] copyWords32 = new long[] { 0xDEADF00DDEADBEEFL, 0xDEADF00DDEADBEEFL }; LongArrayBitVector.wrap( copyWords16, 64 * 2 + 32 ).equals( LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 32 ) ); assertEquals( LongArrayBitVector.wrap( copyWords16, 64 * 2 + 32 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 32 ) ); copyWords16[ 2 ] &= 0xFFFF; assertEquals( LongArrayBitVector.wrap( copyWords16, 64 * 2 + 16 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 16 ) ); copyWords16[ 2 ] &= 0xFF; assertEquals( LongArrayBitVector.wrap( copyWords16, 64 * 2 + 8 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 8 ) ); copyWords16[ 2 ] &= 0x1F; assertEquals( LongArrayBitVector.wrap( copyWords16, 64 * 2 + 5 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 5 ) ); copyWords16[ 2 ] &= 0x1; assertEquals( LongArrayBitVector.wrap( copyWords16, 64 * 2 + 1 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 16, 16 + 64 * 2 + 1 ) ); copyWords32[ 1 ] &= 0xFFFFFFFFFFFFL; assertEquals( LongArrayBitVector.wrap( copyWords32, 64 * 1 + 32 + 16 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 32, 32 + 64 + 32 + 16 ) ); copyWords32[ 1 ] &= 0xFFFFFFFFFFL; assertEquals( LongArrayBitVector.wrap( copyWords32, 64 * 1 + 32 + 8 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 32, 32 + 64 + 32 + 8 ) ); copyWords32[ 1 ] &= 0x1FFFFFFFFFL; assertEquals( LongArrayBitVector.wrap( copyWords32, 64 * 1 + 32 + 5 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 32, 32 + 64 + 32 + 5 ) ); copyWords32[ 1 ] &= 0x1FFFFFFFFL; assertEquals( LongArrayBitVector.wrap( copyWords32, 64 * 1 + 32 + 1 ), LongArrayBitVector.wrap( words, 64 * 3 ).copy( 32, 32 + 64 + 32 + 1 ) ); }
Example #27
Source File: BitVectorTestCase.java From database with GNU General Public License v2.0 | 4 votes |
public static void testAdd( final BitVector v ) { v.clear(); v.size( 100 ); v.add( 0, true ); assertTrue( v.getBoolean( 0 ) ); v.add( 0, true ); assertTrue( v.getBoolean( 0 ) ); assertTrue( v.getBoolean( 1 ) ); v.add( false ); assertTrue( v.getBoolean( 0 ) ); assertTrue( v.getBoolean( 1 ) ); assertFalse( v.getBoolean( 2 ) ); v.set( 1, false ); assertTrue( v.getBoolean( 0 ) ); assertFalse( v.getBoolean( 1 ) ); assertFalse( v.getBoolean( 2 ) ); v.set( 1, true ); assertTrue( v.getBoolean( 0 ) ); assertTrue( v.getBoolean( 1 ) ); assertFalse( v.getBoolean( 2 ) ); v.clear(); v.size( 100 ); v.add( 0, 1 ); assertEquals( 1, v.getInt( 0 ) ); v.add( 0, 2 ); assertEquals( 1, v.getInt( 0 ) ); assertEquals( 1, v.getInt( 1 ) ); v.add( 0, 0 ); assertEquals( 0, v.getInt( 0 ) ); assertEquals( 1, v.getInt( 1 ) ); assertEquals( 1, v.getInt( 2 ) ); v.add( 0 ); assertEquals( 0, v.getInt( 0 ) ); assertEquals( 1, v.getInt( 1 ) ); assertEquals( 1, v.getInt( 2 ) ); assertEquals( 0, v.getInt( 3 ) ); v.set( 1, 0 ); assertEquals( 0, v.getInt( 0 ) ); assertEquals( 0, v.getInt( 1 ) ); assertEquals( 1, v.getInt( 2 ) ); assertEquals( 0, v.getInt( 3 ) ); v.set( 1, 1 ); assertEquals( 0, v.getInt( 0 ) ); assertEquals( 1, v.getInt( 1 ) ); assertEquals( 1, v.getInt( 2 ) ); assertEquals( 0, v.getInt( 3 ) ); v.clear(); v.append( 1, 2 ); v.append( 1, 2 ); v.append( 3, 2 ); assertEquals( LongArrayBitVector.of( 1, 0, 1, 0, 1, 1 ), v ); v.clear(); for( int i = 0; i < 80; i++ ) v.add( 0, true ); for( int i = 0; i < 80; i++ ) assertTrue( v.getBoolean( i ) ); v.clear(); for( int i = 0; i < 80; i++ ) v.add( 0, false ); for( int i = 0; i < 80; i++ ) assertFalse( v.getBoolean( i ) ); }
Example #28
Source File: TableWriter.java From mph-table with Apache License 2.0 | 4 votes |
private static <K, V> void writeWithMinimalPerfectHashFunction( final File inputData, final File outputDir, final TableConfig origConfig, final Iterable<Pair<K, V>> entries, final GOVMinimalPerfectHashFunction<K> mph, final List<K> minMaxKeys, final long dataSize) throws IOException { final TableConfig config = TableConfig.OffsetStorage.AUTOMATIC.equals(origConfig.getOffsetStorage()) ? origConfig.withOffsetStorage(origConfig.chooseBestOffsetStorage(mph.size(), dataSize)) : origConfig; final byte[] minKey = maybeSerializeKey(config, minMaxKeys.get(0)); final byte[] maxKey = maybeSerializeKey(config, minMaxKeys.get(1)); final TableMeta<K, V> meta; switch (config.getOffsetStorage()) { case FIXED: LOGGER.info("writing with fixed offset storage: " + config); meta = new TableMeta(config, mph, null, minKey, maxKey, dataSize); writeToHashOffsets(outputDir, meta, entries, dataSize); break; case INDEXED: LOGGER.info("writing with indexed offset storage: " + config); meta = new TableMeta(config, mph, null, minKey, maxKey, dataSize); writeToIndexedOffsets(inputData, new File(outputDir, meta.DEFAULT_DATA_PATH), new File(outputDir, meta.DEFAULT_OFFSETS_PATH), meta, entries, dataSize); break; case SELECTED: LOGGER.info("writing with selected offset storage: " + config); final File sizes = writeToHashOffsets(outputDir, new TableMeta(config, mph, null, dataSize), entries, dataSize); final Select select = sizesToSelect(config, sizes, dataSize); sizes.delete(); if (select.bitVector() instanceof LongArrayBitVector && (config.getMaxHeapUsage() > 0 && select.numBits() / 8L > config.getMaxHeapUsage())) { meta = new TableMeta(config, mph, null, minKey, maxKey, dataSize); writeLongs(new File(outputDir, meta.DEFAULT_OFFSETS_PATH), select.bitVector().bits()); } else { meta = new TableMeta(config, mph, select, minKey, maxKey, dataSize); } break; default: throw new IllegalArgumentException("unknown offset storage: " + config.getOffsetStorage()); } meta.store(new File(outputDir, meta.DEFAULT_META_PATH)); }
Example #29
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 4 votes |
public void testReplaceLongArrayBitVector() { LongArrayBitVector b = LongArrayBitVector.of( 0, 1, 1 ); assertEquals( b, LongArrayBitVector.getInstance().replace( b ) ); }
Example #30
Source File: LongArrayBitVectorTest.java From database with GNU General Public License v2.0 | 4 votes |
public void testLogicOperators() { BitVectorTestCase.testLogicOperators( LongArrayBitVector.getInstance() ); }