blob: fee505e2c69551e2d2ac954cc4ae25c22abeb37b (
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
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/searchlib/common/tunefileinfo.h>
#include <vespa/vespalib/util/array.h>
#include <vespa/vespalib/stllike/string.h>
#include <limits>
namespace search::diskindex {
class WordNumMapper;
class WordNumMapping
{
using Array = vespalib::Array<uint64_t>;
static uint64_t noWordNumHigh() {
return std::numeric_limits<uint64_t>::max();
}
static uint64_t noWordNum() { return 0u; }
Array _old2newwords;
uint64_t _oldDictSize;
public:
WordNumMapping();
const uint64_t *getOld2NewWordNums() const {
return (_old2newwords.empty())
? nullptr
: &_old2newwords[0];
}
uint64_t getOldDictSize() const { return _oldDictSize; }
void readMappingFile(const vespalib::string &name, const TuneFileSeqRead &tuneFileRead);
void noMappingFile();
void clear();
void setup(uint32_t numWordIds);
};
class WordNumMapper
{
static uint64_t noWordNumHigh() {
return std::numeric_limits<uint64_t>::max();
}
static uint64_t noWordNum() { return 0u; }
const uint64_t *_old2newwords;
uint64_t _oldDictSize;
public:
WordNumMapper()
: _old2newwords(nullptr),
_oldDictSize(0)
{}
void setup(const WordNumMapping &mapping) {
_old2newwords = mapping.getOld2NewWordNums();
_oldDictSize = mapping.getOldDictSize();
}
uint64_t map(uint32_t wordNum) const {
return (_old2newwords != nullptr)
? _old2newwords[wordNum]
: wordNum;
}
};
}
|