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

#pragma once

#include <vespa/vespalib/datastore/aligner.h>
#include <vespa/vespalib/datastore/datastore.h>
#include <vespa/vespalib/stllike/string.h>

namespace search::memoryindex {

class WordStore {
public:
    using DataStoreType = vespalib::datastore::DataStoreT<vespalib::datastore::EntryRefT<22>>;
    using RefType = DataStoreType::RefType;
    static constexpr uint32_t buffer_array_size = 4u; // Must be a power of 2
    using Aligner = vespalib::datastore::Aligner<buffer_array_size>;

private:
    DataStoreType           _store;
    uint32_t                _numWords;
    vespalib::datastore::BufferType<char> _type;
    const uint32_t          _typeId;

public:
    WordStore();
    ~WordStore();
    vespalib::datastore::EntryRef addWord(const vespalib::stringref word);
    const char *getWord(vespalib::datastore::EntryRef ref) const {
        RefType internalRef(ref);
        return _store.getEntryArray<char>(internalRef, buffer_array_size);
    }

    vespalib::MemoryUsage getMemoryUsage() const {
        return _store.getMemoryUsage();
    }
};

}