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

/**
 * Conjunction id posting list iterator for a single feature/assignment (e.g. a=b).
 *
 * @author bjorncs
 */
public class ConjunctionIdIterator {

    private final int[] conjunctionIds;
    private final long subqueryBitmap;
    private int currentConjunctionId;
    private int length;
    private int index;

    public ConjunctionIdIterator(long subqueryBitmap, int[] conjunctionIds) {
        this.subqueryBitmap = subqueryBitmap;
        this.conjunctionIds = conjunctionIds;
        this.currentConjunctionId = conjunctionIds[0];
        this.length = conjunctionIds.length;
        this.index = 0;
    }

    public boolean next(int conjunctionId) {
        if (index == length) return false;

        int candidate = currentConjunctionId;
        while (ConjunctionId.compare(conjunctionId, candidate) > 0 && ++index < length) {
            candidate = conjunctionIds[index];
        }
        currentConjunctionId = candidate;
        return ConjunctionId.compare(conjunctionId, candidate) <= 0;
    }

    public long getSubqueryBitmap() {
        return subqueryBitmap;
    }

    public int getConjunctionId() {
        return currentConjunctionId;
    }

    public int[] getConjunctionIds() {
        return conjunctionIds;
    }

}