MCPcopy Create free account
hub / github.com/apache/solr / BitDocSet

Class BitDocSet

solr/core/src/java/org/apache/solr/search/BitDocSet.java:33–346  ·  view source on GitHub ↗

A FixedBitSet based implementation of a DocSet. Good for medium/large sets. @since solr 0.9

Source from the content-addressed store, hash-verified

31 *
32 * @since solr 0.9
33 */
34public class BitDocSet extends DocSet {
35 // for the array object inside the FixedBitSet. long[] array won't change alignment, so no need to
36 // calculate it.
37 private static final long BASE_RAM_BYTES_USED =
38 RamUsageEstimator.shallowSizeOfInstance(BitDocSet.class)
39 + RamUsageEstimator.shallowSizeOfInstance(FixedBitSet.class)
40 + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER;
41
42 // TODO consider SparseFixedBitSet alternative
43
44 private final FixedBitSet bits;
45 int size; // number of docs in the set (cached for perf)
46
47 public BitDocSet() {
48 bits = new FixedBitSet(64);
49 }
50
51 /** Construct a BitDocSet. The capacity of the {@link FixedBitSet} should be at least maxDoc() */
52 public BitDocSet(FixedBitSet bits) {
53 this.bits = bits;
54 size = -1;
55 }
56
57 /**
58 * Construct a BitDocSet, and provides the number of set bits. The capacity of the {@link
59 * FixedBitSet} should be at least maxDoc()
60 */
61 public BitDocSet(FixedBitSet bits, int size) {
62 this.bits = bits;
63 this.size = size;
64 }
65
66 @Override
67 public DocIterator iterator() {
68 return new DocIterator() {
69 private final BitSetIterator iter = new BitSetIterator(bits, 0L); // cost is not useful here
70 private int pos = iter.nextDoc();
71
72 @Override
73 public boolean hasNext() {
74 return pos != DocIdSetIterator.NO_MORE_DOCS;
75 }
76
77 @Override
78 public Integer next() {
79 return nextDoc();
80 }
81
82 @Override
83 public void remove() {
84 bits.clear(pos);
85 }
86
87 @Override
88 public int nextDoc() {
89 int old = pos;
90 pos = iter.nextDoc();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…