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

Class SortedIntDocSet

solr/core/src/java/org/apache/solr/search/SortedIntDocSet.java:32–787  ·  view source on GitHub ↗

A simple sorted int[] array implementation of DocSet, good for small sets.

Source from the content-addressed store, hash-verified

30
31/** A simple sorted int[] array implementation of {@link DocSet}, good for small sets. */
32public class SortedIntDocSet extends DocSet {
33 private static final long BASE_RAM_BYTES_USED =
34 RamUsageEstimator.shallowSizeOfInstance(SortedIntDocSet.class)
35 + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER;
36
37 protected final int[] docs;
38
39 /**
40 * @param docs Sorted list of ids
41 */
42 public SortedIntDocSet(int[] docs) {
43 this.docs = docs;
44 }
45
46 /**
47 * @param docs Sorted list of ids
48 * @param len Number of ids in the list
49 */
50 public SortedIntDocSet(int[] docs, int len) {
51 this(shrink(docs, len));
52 }
53
54 public int[] getDocs() {
55 return docs;
56 }
57
58 @Override
59 public int size() {
60 return docs.length;
61 }
62
63 public static int[] zeroInts = new int[0];
64 public static SortedIntDocSet zero = new SortedIntDocSet(zeroInts);
65
66 public static int[] shrink(int[] arr, int newSize) {
67 if (arr.length == newSize) return arr;
68 int[] newArr = new int[newSize];
69 System.arraycopy(arr, 0, newArr, 0, newSize);
70 return newArr;
71 }
72
73 public static int intersectionSize(int[] smallerSortedList, int[] biggerSortedList) {
74 final int a[] = smallerSortedList;
75 final int b[] = biggerSortedList;
76
77 // The next doc we are looking for will be much closer to the last position we tried
78 // than it will be to the midpoint between last and high... so probe ahead using
79 // a function of the ratio of the sizes of the sets.
80 int step = (b.length / a.length) + 1;
81
82 // Since the majority of probes should be misses, we'll already be above the last probe
83 // and shouldn't need to move larger than the step size on average to step over our target (and
84 // thus lower the high upper bound a lot.)... but if we don't go over our target, it's a big
85 // miss... so double it.
86 step = step + step;
87
88 // FUTURE: come up with a density such that target * density == likely position?
89 // then check step on one side or the other?

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…