aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/reference.h
blob: 8f9a369f13f24424e9a6f573f6e0ededa6785a22 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/document/base/globalid.h>
#include <vespa/vespalib/datastore/entryref.h>

namespace search::attribute {

/*
 * Class representing a single reference in a reference attribute.
 */
class Reference {
    using EntryRef = vespalib::datastore::EntryRef;
    using GlobalId = document::GlobalId;
    GlobalId _gid;
    mutable uint32_t _lid;  // target lid
    mutable EntryRef _revMapIdx; // map from gid to lids referencing gid
public:
    Reference()
        : _gid(),
          _lid(0u),
          _revMapIdx()
    {
    }
    Reference(const GlobalId &gid_)
        : _gid(gid_),
          _lid(0u),
          _revMapIdx()
    {
    }
    bool operator < (const Reference &rhs) const {
        return _gid < rhs._gid;
    }
    bool operator == (const Reference &rhs) const {
        return _gid == rhs._gid;
    }
    const GlobalId &gid() const { return _gid; }
    uint32_t lid() const { return _lid; }
    EntryRef revMapIdx() const { return _revMapIdx; }
    void setLid(uint32_t targetLid) const { _lid = targetLid; }
    void setRevMapIdx(EntryRef newRevMapIdx) const { _revMapIdx = newRevMapIdx; }
    size_t hash() const noexcept {
        GlobalId::hash hasher;
        return hasher(_gid);
    }
};

}