blob: 37744657d9fc256a60678d5dcaa05ceefe8407c3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.predicate.index;
import com.yahoo.search.predicate.utils.PostingListSearch;
/**
* Shared implementation for posting lists that may have multiple intervals.
*
* @author Magnar Nedland
* @author bjorncs
*/
public abstract class MultiIntervalPostingList implements PostingList {
private final int[] docIds;
private final int[] dataRefs;
private final long subquery;
private final int length;
private int currentIndex;
private int currentDocId;
public MultiIntervalPostingList(int[] docIds, int[] dataRefs, long subquery) {
this.docIds = docIds;
this.dataRefs = dataRefs;
this.subquery = subquery;
this.length = docIds.length;
this.currentIndex = 0;
this.currentDocId = -1;
}
@Override
public final boolean nextDocument(int docId) {
int index = currentIndex;
index = PostingListSearch.interpolationSearch(docIds, index, length, docId);
if (index == length) {
return false;
}
this.currentDocId = docIds[index];
this.currentIndex = index;
assert currentDocId > docId;
return true;
}
@Override
public final boolean prepareIntervals() {
return prepareIntervals(dataRefs[currentIndex]);
}
protected abstract boolean prepareIntervals(int dataRef);
@Override
public final int size() {
return length;
}
@Override
public final int getDocId() {
return currentDocId;
}
@Override
public final int[] getDocIds() {
return docIds;
}
@Override
public final long getSubquery() {
return subquery;
}
}
|