List of usage examples for org.apache.lucene.util IntsRef IntsRef
public IntsRef(int capacity)
capacity. From source file:com.sindicetech.siren.index.codecs.block.TestAForCodec.java
License:Open Source License
@Test public void testIncompleteFrame() throws IOException { final BlockCompressor compressor = new AForBlockCompressor(); final IntsRef input = new IntsRef(64); final BytesRef output = new BytesRef(compressor.maxCompressedSize(64)); // fill first part with 1 for (int i = 0; i < 33; i++) { input.ints[i] = 1;/*from w w w . ja v a 2s. c o m*/ } // fill the rest with random numbers for (int i = 33; i < 64; i++) { input.ints[i] = (int) this.nextLong(64, Short.MAX_VALUE); } input.offset = 0; input.length = 33; // the random numbers after the end of the input array should not impact // compression compressor.compress(input, output); // should be frame code 1 : 32 ints encoded with 1 bits assertEquals(1, output.bytes[0]); // followed by 4 bytes at 255 assertEquals(0xFF, output.bytes[1] & 0xFF); assertEquals(0xFF, output.bytes[2] & 0xFF); assertEquals(0xFF, output.bytes[3] & 0xFF); assertEquals(0xFF, output.bytes[4] & 0xFF); // then frame code 34 : 16 ints encoded with 1 bits assertEquals(34, output.bytes[5]); // followed by 1 byte with at least 128 and a second byte with 0 assertEquals(128, output.bytes[6] & 0x80); assertEquals(0, output.bytes[7] & 0xFF); // followed by frame code 33: 16 ints encoded with 0 bits assertEquals(33, output.bytes[8]); }
From source file:com.sindicetech.siren.index.codecs.CodecTestCase.java
License:Open Source License
private void doTest(final int[] values, final int blockSize, final BlockCompressor compressor, final BlockDecompressor decompressor) throws Exception { final BytesRef compressedData = new BytesRef(compressor.maxCompressedSize(blockSize)); final IntsRef input = new IntsRef(blockSize); final IntsRef output = new IntsRef(blockSize); for (int i = 0; i < values.length; i += blockSize) { int offset = 0; // copy first block into the uncompressed data buffer for (int j = i; offset < blockSize && j < values.length; j++, offset++) { input.ints[offset] = values[j]; }//w w w . j a v a 2 s. co m input.offset = 0; input.length = offset; // compress compressor.compress(input, compressedData); // decompress decompressor.decompress(compressedData, output); // check if they are equals for (int j = 0; j < input.length; j++) { assertEquals(input.ints[j], output.ints[j]); } } }
From source file:elhuyar.bilakit.Dictionary.java
License:Apache License
private FST<IntsRef> affixFST(TreeMap<String, List<Integer>> affixes) throws IOException { IntSequenceOutputs outputs = IntSequenceOutputs.getSingleton(); Builder<IntsRef> builder = new Builder<>(FST.INPUT_TYPE.BYTE4, outputs); IntsRefBuilder scratch = new IntsRefBuilder(); for (Map.Entry<String, List<Integer>> entry : affixes.entrySet()) { Util.toUTF32(entry.getKey(), scratch); List<Integer> entries = entry.getValue(); IntsRef output = new IntsRef(entries.size()); for (Integer c : entries) { output.ints[output.length++] = c; }/*w w w . java 2s. c o m*/ builder.add(scratch.get(), output); } return builder.finish(); }
From source file:org.opensextant.solrtexttagger.TermPrefixCursor.java
License:Open Source License
/** Returns an IntsRef either cached or reading postingsEnum. Not null. * @param postingsEnum*/// w w w.j a v a2 s . co m private IntsRef postingsEnumToIntsRef(PostingsEnum postingsEnum, Bits liveDocs) throws IOException { // (The cache can have empty IntsRefs) //lookup prefixBuf in a cache if (docIdsCache != null) { docIds = docIdsCache.get(prefixBuf); if (docIds != null) { return docIds; } } //read postingsEnum docIds = new IntsRef(termsEnum.docFreq()); int docId; while ((docId = postingsEnum.nextDoc()) != PostingsEnum.NO_MORE_DOCS) { if (liveDocs != null && !liveDocs.get(postingsEnum.docID())) { continue; } docIds.ints[docIds.length++] = docId; } if (docIds.length == 0) docIds = EMPTY_INTSREF; //cache if (docIdsCache != null) { ensureBufIsACopy(); //clone is shallow; that's okay as the prefix isn't overwritten; it's just appended to docIdsCache.put(prefixBuf.clone(), docIds); } return docIds; }