Package org.apache.lucene.util
Class DocIdSetBuilder
- java.lang.Object
-
- org.apache.lucene.util.DocIdSetBuilder
-
public final class DocIdSetBuilder extends java.lang.Object
A builder ofDocIdSet
s. At first it uses a sparse structure to gather documents, and then upgrades to a non-sparse bit set once enough hits match. To add documents, you first need to callgrow(int)
in order to reserve space, and then callDocIdSetBuilder.BulkAdder.add(int)
on the returnedDocIdSetBuilder.BulkAdder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DocIdSetBuilder.Buffer
private static class
DocIdSetBuilder.BufferAdder
static class
DocIdSetBuilder.BulkAdder
Utility class to efficiently add many docs in one go.private static class
DocIdSetBuilder.FixedBitSetAdder
-
Field Summary
Fields Modifier and Type Field Description private DocIdSetBuilder.BulkAdder
adder
private FixedBitSet
bitSet
private java.util.List<DocIdSetBuilder.Buffer>
buffers
private long
counter
private int
maxDoc
(package private) boolean
multivalued
(package private) double
numValuesPerDoc
private int
threshold
private int
totalAllocated
-
Constructor Summary
Constructors Constructor Description DocIdSetBuilder(int maxDoc)
Create a builder that can contain doc IDs between0
andmaxDoc
.DocIdSetBuilder(int maxDoc, int docCount, long valueCount)
DocIdSetBuilder(int maxDoc, PointValues values, java.lang.String field)
Create aDocIdSetBuilder
instance that is optimized for accumulating docs that match the givenPointValues
.DocIdSetBuilder(int maxDoc, Terms terms)
Create aDocIdSetBuilder
instance that is optimized for accumulating docs that match the givenTerms
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(DocIdSetIterator iter)
Add the content of the providedDocIdSetIterator
to this builder.private DocIdSetBuilder.Buffer
addBuffer(int len)
private int
additionalCapacity(int numDocs)
DocIdSet
build()
Build aDocIdSet
from the accumulated doc IDs.private static DocIdSetBuilder.Buffer
concat(java.util.List<DocIdSetBuilder.Buffer> buffers)
Concatenate the buffers in any order, leaving at least one empty slot in the end NOTE: this method might reuse one of the arraysprivate static int
dedup(int[] arr, int length)
private void
ensureBufferCapacity(int numDocs)
DocIdSetBuilder.BulkAdder
grow(int numDocs)
Reserve space and return aDocIdSetBuilder.BulkAdder
object that can be used to add up tonumDocs
documents.private void
growBuffer(DocIdSetBuilder.Buffer buffer, int additionalCapacity)
private static boolean
noDups(int[] a, int len)
private void
upgradeToBitSet()
-
-
-
Field Detail
-
maxDoc
private final int maxDoc
-
threshold
private final int threshold
-
multivalued
final boolean multivalued
-
numValuesPerDoc
final double numValuesPerDoc
-
buffers
private java.util.List<DocIdSetBuilder.Buffer> buffers
-
totalAllocated
private int totalAllocated
-
bitSet
private FixedBitSet bitSet
-
counter
private long counter
-
adder
private DocIdSetBuilder.BulkAdder adder
-
-
Constructor Detail
-
DocIdSetBuilder
public DocIdSetBuilder(int maxDoc)
Create a builder that can contain doc IDs between0
andmaxDoc
.
-
DocIdSetBuilder
public DocIdSetBuilder(int maxDoc, Terms terms) throws java.io.IOException
Create aDocIdSetBuilder
instance that is optimized for accumulating docs that match the givenTerms
.- Throws:
java.io.IOException
-
DocIdSetBuilder
public DocIdSetBuilder(int maxDoc, PointValues values, java.lang.String field) throws java.io.IOException
Create aDocIdSetBuilder
instance that is optimized for accumulating docs that match the givenPointValues
.- Throws:
java.io.IOException
-
DocIdSetBuilder
DocIdSetBuilder(int maxDoc, int docCount, long valueCount)
-
-
Method Detail
-
add
public void add(DocIdSetIterator iter) throws java.io.IOException
Add the content of the providedDocIdSetIterator
to this builder. NOTE: if you need to build aDocIdSet
out of a singleDocIdSetIterator
, you should rather useRoaringDocIdSet.Builder
.- Throws:
java.io.IOException
-
grow
public DocIdSetBuilder.BulkAdder grow(int numDocs)
Reserve space and return aDocIdSetBuilder.BulkAdder
object that can be used to add up tonumDocs
documents.
-
ensureBufferCapacity
private void ensureBufferCapacity(int numDocs)
-
additionalCapacity
private int additionalCapacity(int numDocs)
-
addBuffer
private DocIdSetBuilder.Buffer addBuffer(int len)
-
growBuffer
private void growBuffer(DocIdSetBuilder.Buffer buffer, int additionalCapacity)
-
upgradeToBitSet
private void upgradeToBitSet()
-
concat
private static DocIdSetBuilder.Buffer concat(java.util.List<DocIdSetBuilder.Buffer> buffers)
Concatenate the buffers in any order, leaving at least one empty slot in the end NOTE: this method might reuse one of the arrays
-
dedup
private static int dedup(int[] arr, int length)
-
noDups
private static boolean noDups(int[] a, int len)
-
-