summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/enumattribute.h
blob: 4753dbe65f902aee66c6d63fc197a786a70bb689 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "attributevector.h"
#include "loadedenumvalue.h"
#include "enumstore.h"
#include "no_loaded_vector.h"

namespace search {

template <typename B>
class EnumAttribute : public B
{
protected:
    using BaseClass = B;
    using Change = typename B::Change;
    using ChangeVector = typename B::ChangeVector;
    using DocId = typename B::DocId;
    using EnumEntryType = typename B::EnumEntryType;  // Template argument for enum store
    using EnumHandle = typename B::EnumHandle;
    using ValueModifier = typename B::ValueModifier;

public:
    using EnumVector = typename B::EnumVector;
    using LoadedVector = typename B::LoadedVector;

protected:
    using generation_t = typename B::generation_t;
    using B::getGenerationHolder;

public:
    using EnumStore = EnumStoreT<EnumEntryType>;
    using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater;

protected:
    using EnumIndex = IEnumStore::Index;

    EnumStore _enumStore;

    const IEnumStore* getEnumStoreBase() const override { return &_enumStore; }
    IEnumStore* getEnumStoreBase() override { return &_enumStore; }
    EnumEntryType getFromEnum(EnumHandle e) const override { return _enumStore.get_value(e); }

    void load_posting_lists(LoadedVector& loaded) override { (void) loaded; }
    void load_enum_store(LoadedVector& loaded) override;
    uint64_t getUniqueValueCount() const override;

    EnumEntryType getDefaultEnumTypeValue() { return B::defaultValue(); }

    /*
     * Iterate through the change vector and find new unique values.
     * Insert the new unique values into the EnumStore.
     */
    void insertNewUniqueValues(EnumStoreBatchUpdater& updater);
    virtual void considerAttributeChange(const Change & c, EnumStoreBatchUpdater & inserter) = 0;
    vespalib::MemoryUsage getEnumStoreValuesMemoryUsage() const override;
    void populate_address_space_usage(AddressSpaceUsage& usage) const override;
public:
    EnumAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & cfg);
    ~EnumAttribute();
    bool findEnum(EnumEntryType v, EnumHandle & e) const override { return _enumStore.find_enum(v, e); }
    const EnumStore & getEnumStore() const { return _enumStore; }
    EnumStore &       getEnumStore()       { return _enumStore; }
};

} // namespace search