aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search/src/main/java/com/yahoo/search/predicate/index/ZeroConstraintPostingList.java
blob: 18af4413d36cde9e21c3a8e76050f45178b8d425 (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
71
72
73
74
75
// Copyright Vespa.ai. 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.SubqueryBitmap;

/**
 * Wraps an int stream of document ids into a PostingList.
 * All documents in the stream are considered matches.
 *
 * @author Magnar Nedland
 * @author bjorncs
 */
public class ZeroConstraintPostingList implements PostingList {

    private final int[] docIds;
    private final int length;
    private int currentIndex;
    private int currentDocId;

    public ZeroConstraintPostingList(int[] docIds) {
        this.docIds = docIds;
        this.currentIndex = 0;
        this.currentDocId = -1;
        this.length = docIds.length;
    }

    @Override
    public boolean nextDocument(int docId) {
        int currentDocId = this.currentDocId;
        while (currentIndex < length && currentDocId <= docId) {
            currentDocId = docIds[currentIndex++];
        }
        if (currentDocId <= docId) {
            return false;
        }
        this.currentDocId = currentDocId;
        return true;
    }

    @Override
    public boolean prepareIntervals() {
        return true;
    }

    @Override
    public boolean nextInterval() {
        return false;
    }

    @Override
    public int size() {
        return length;
    }

    @Override
    public int getInterval() {
        return Interval.fromBoundaries(1, Interval.ZERO_CONSTRAINT_RANGE);
    }

    @Override
    public int getDocId() {
        return currentDocId;
    }

    @Override
    public long getSubquery() {
        return SubqueryBitmap.ALL_SUBQUERIES;
    }

    @Override
    public int[] getDocIds() {
        return docIds;
    }

}