aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search/src/main/java/com/yahoo/search/predicate/index/IntervalPostingList.java
blob: 6ae00817dd04a31e0a8895702751f99b536b7063 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.predicate.index;

/**
 * Implementation of PostingList for regular features that store
 * their intervals and nothing else.
 *
 * @author Magnar Nedland
 * @author bjorncs
 */
public class IntervalPostingList extends MultiIntervalPostingList {

    private final PredicateIntervalStore store;
    private int[] currentIntervals;
    private int currentIntervalIndex;
    private int currentInterval;

    public IntervalPostingList(PredicateIntervalStore store, int[] docIds, int[] dataRefs, long subquery) {
        super(docIds, dataRefs, subquery);
        this.store = store;
    }

    @Override
    protected boolean prepareIntervals(int dataRef) {
        currentIntervals = store.get(dataRef);
        currentIntervalIndex = 1;
        currentInterval = currentIntervals[0];
        return true;
    }

    @Override
    public boolean nextInterval() {
        if (currentIntervalIndex < currentIntervals.length) {
            this.currentInterval = currentIntervals[currentIntervalIndex++];
            return true;
        }
        return false;
    }

    @Override
    public int getInterval() {
        return currentInterval;
    }

}