blob: 8141a16c13787f0962b7de495156964b53b2cc2c (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2017 Yahoo Holdings. 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
{
typedef vespalib::Array<uint64_t> Array;
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())
? NULL
: &_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);
uint64_t getMaxMappedWordNum() const;
void sanityCheck(bool allowHoles);
};
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(NULL),
_oldDictSize(0)
{}
WordNumMapper(const WordNumMapping &mapping)
: _old2newwords(NULL),
_oldDictSize(0)
{
setup(mapping);
}
void setup(const WordNumMapping &mapping) {
_old2newwords = mapping.getOld2NewWordNums();
_oldDictSize = mapping.getOldDictSize();
}
uint64_t map(uint32_t wordNum) const {
return (_old2newwords != NULL)
? _old2newwords[wordNum]
: wordNum;
}
uint64_t getMaxWordNum() const { return _oldDictSize; }
uint64_t getMaxMappedWordNum() const { return map(_oldDictSize); }
void sanityCheck(bool allowHoles);
};
}
|