aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search/src/main/java/com/yahoo/search/predicate/index/conjunction/ConjunctionHit.java
blob: cfdbb9fc790286306edc22376f34dd45d51c491e (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
// 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.conjunction;

import com.yahoo.search.predicate.SubqueryBitmap;

/**
 * Represents a conjunction hit. See {@link ConjunctionIndex}.
 *
 * @author bjorncs
 */
public class ConjunctionHit implements Comparable<ConjunctionHit> {

    public final long conjunctionId;
    public final long subqueryBitmap;

    public ConjunctionHit(long conjunctionId, long subqueryBitmap) {
        this.conjunctionId = conjunctionId;
        this.subqueryBitmap = subqueryBitmap;
    }

    @Override
    public int compareTo(ConjunctionHit other) {
        return Long.compareUnsigned(conjunctionId, other.conjunctionId);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ConjunctionHit that = (ConjunctionHit) o;

        if (conjunctionId != that.conjunctionId) return false;
        return subqueryBitmap == that.subqueryBitmap;

    }

    @Override
    public int hashCode() {
        int result = (int) (conjunctionId ^ (conjunctionId >>> 32));
        result = 31 * result + (int) (subqueryBitmap ^ (subqueryBitmap >>> 32));
        return result;
    }

    @Override
    public String toString() {
        if (subqueryBitmap == SubqueryBitmap.DEFAULT_VALUE) {
            return "" + conjunctionId;
        } else {
            return "[" + conjunctionId + ",0x" + Long.toHexString(subqueryBitmap) + "]";
        }
    }

}