it.unimi.dsi.fastutil.chars.CharArrayList Java Examples

The following examples show how to use it.unimi.dsi.fastutil.chars.CharArrayList. 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: TextPatternTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testSearch() {
	byte[] b = new byte[] { 1, (byte)'A', 'B', 2 };
	String s = " AB ";
	TextPattern pattern = new TextPattern( "AB" );
	
	assertEquals( -1, pattern.search( b, 0, 2 ) );	
	assertEquals( -1, pattern.search( s, 0, 2 ) );	
	assertEquals( -1, pattern.search( s.toCharArray(), 0, 2 ) );	
	assertEquals( -1, pattern.search( CharArrayList.wrap( s.toCharArray() ), 0, 2 ) );	
	
	assertEquals( 1, pattern.search( b ) );	
	assertEquals( 1, pattern.search( s ) );	
	assertEquals( 1, pattern.search( s.toCharArray() ) );	
	assertEquals( 1, pattern.search( CharArrayList.wrap( s.toCharArray() ) ) );	

	TextPattern patternMeta = new TextPattern( "<meta", TextPattern.CASE_INSENSITIVE );
	assertTrue( patternMeta.search( documentMetaIsutf_8.getBytes() ) != -1 );
	patternMeta = new TextPattern( "<META", TextPattern.CASE_INSENSITIVE );
	assertTrue( patternMeta.search( documentMetaIsutf_8.getBytes() ) != -1 );
	
}
 
Example #2
Source File: AvroRecordConverter.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
public void end() {
  if (elementClass == boolean.class) {
    parent.add(((BooleanArrayList) container).toBooleanArray());
  } else if (elementClass == byte.class) {
    parent.add(((ByteArrayList) container).toByteArray());
  } else if (elementClass == char.class) {
    parent.add(((CharArrayList) container).toCharArray());
  } else if (elementClass == short.class) {
    parent.add(((ShortArrayList) container).toShortArray());
  } else if (elementClass == int.class) {
    parent.add(((IntArrayList) container).toIntArray());
  } else if (elementClass == long.class) {
    parent.add(((LongArrayList) container).toLongArray());
  } else if (elementClass == float.class) {
    parent.add(((FloatArrayList) container).toFloatArray());
  } else if (elementClass == double.class) {
    parent.add(((DoubleArrayList) container).toDoubleArray());
  } else {
    parent.add(((ArrayList) container).toArray());
  }
}
 
Example #3
Source File: TextPatternTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void testSingleCharacterSearch() {
	byte[] b = new byte[] { 1, (byte)'A', 2 };
	String s = " A ";
	TextPattern pattern = new TextPattern( "A" );

	assertEquals( -1, pattern.search( b, 0, 1 ) );	
	assertEquals( -1, pattern.search( s, 0, 1 ) );	
	assertEquals( -1, pattern.search( s.toCharArray(), 0, 1 ) );	
	assertEquals( -1, pattern.search( CharArrayList.wrap( s.toCharArray() ), 0, 1 ) );	

	assertEquals( 1, pattern.search( b ) );	
	assertEquals( 1, pattern.search( s ) );	
	assertEquals( 1, pattern.search( s.toCharArray() ) );	
	assertEquals( 1, pattern.search( CharArrayList.wrap( s.toCharArray() ) ) );	
}
 
Example #4
Source File: ImmutableBTreeIndex.java    From lsmtree with Apache License 2.0 4 votes vote down vote up
private static <K,V> WriteLevelResult writeLevel(
        final CountingOutputStream counter,
        final Path tempPath,
        final Iterator<Generation.Entry<K,V>> iterator,
        final Serializer<K> keySerializer,
        final Serializer<V> valueSerializer,
        final int blocksize,
        final boolean keepDeletions
) throws IOException {
    Generation.Entry<K,V> next;
    if (!iterator.hasNext()) {
        return new WriteLevelResult(0, 0);
    }
    next = iterator.next();
    final LittleEndianDataOutputStream tmpOut = new LittleEndianDataOutputStream(new BufferedOutputStream(Files.newOutputStream(tempPath), 131072));
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final LittleEndianDataOutputStream bufferDataOutput = new LittleEndianDataOutputStream(buffer);
    final ByteArrayOutputStream currentBlock = new ByteArrayOutputStream(blocksize);
    final CharArrayList keyOffsets = new CharArrayList();
    int tmpCount = 0;
    boolean done = false;
    final LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(counter);
    long count = 0;
    outer: while (!done) {

        currentBlock.reset();
        keyOffsets.clear();
        if (!keepDeletions) {
            while (next.isDeleted()) {
                if (!iterator.hasNext()) break outer;
                next = iterator.next();
            }
        }
        keySerializer.write(next.getKey(), tmpOut);
        tmpOut.writeLong(counter.getCount());
        tmpCount++;
        while (true) {
            buffer.reset();
            final boolean skipDeleted = updateBuffer(next, keySerializer, valueSerializer, keepDeletions, bufferDataOutput);
            if (4+2*keyOffsets.size()+2+currentBlock.size()+buffer.size() > blocksize) {
                if (currentBlock.size() == 0) {
                    throw new IllegalArgumentException("key value pair is greater than block size");
                }
                break;
            }
            if (!skipDeleted) {
                keyOffsets.add((char)currentBlock.size());
                buffer.writeTo(currentBlock);
                count++;
            }
            if (!iterator.hasNext()) {
                done = true;
                break;
            }
            next = iterator.next();
        }
        if (keyOffsets.size() > 0) {
            final long start = counter.getCount();
            out.writeInt(keyOffsets.size());
            for (int i = 0; i < keyOffsets.size(); i++) {
                out.writeChar(keyOffsets.getChar(i));
            }
            currentBlock.writeTo(out);
            if (counter.getCount()-start > blocksize) {
                log.error("too big");
            }
        }
    }
    tmpOut.close();
    return new WriteLevelResult(tmpCount, count);
}