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

/**
 * Represents an entry in a posting list, containing an integer id and integer data reference.
 *
 * @author Magnar Nedland
 */
public class Posting implements Comparable<Posting> {

    private final int id;
    private final int dataRef;

    public Posting(int id, int dataRef) {
        this.id = id;
        this.dataRef = dataRef;
    }

    public int getId() {
        return id;
    }

    public int getDataRef() {
        return dataRef;
    }

    @Override
    public int compareTo(Posting o) {
        return Integer.compareUnsigned(id, o.id);
    }

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

        Posting posting = (Posting) o;

        if (id != posting.id) return false;
        return dataRef == posting.dataRef;

    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + dataRef;
        return result;
    }

}