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

/**
 * Wraps a posting stream of IntervalWithBounds objects (for collapsed
 * fixed tree leaf nodes) into a PostingList.
 *
 * @author Magnar Nedland
 * @author bjorncs
 */
public class BoundsPostingList extends MultiIntervalPostingList {
    private final int valueDiff;
    private final IntervalWithBounds intervalWithBounds = new IntervalWithBounds();
    private final PredicateIntervalStore store;
    private int currentInterval;

    /**
     * @param valueDiff Difference from the collapsed leaf node's actual value.
     */
    public BoundsPostingList(PredicateIntervalStore store, int[] docIds, int[] dataRefs, long subquery, int valueDiff) {
        super(docIds, dataRefs, subquery);
        this.valueDiff = valueDiff;
        this.store = store;
    }

    @Override
    protected boolean prepareIntervals(int dataRef) {
        intervalWithBounds.setIntervalArray(store.get(dataRef), 0);
        return nextInterval();
    }

    @Override
    public boolean nextInterval() {
        while (intervalWithBounds.hasValue()) {
            if (intervalWithBounds.contains(valueDiff)) {
                this.currentInterval = intervalWithBounds.getInterval();
                intervalWithBounds.nextValue();
                return true;
            }
            intervalWithBounds.nextValue();
        }
        return false;
    }

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