blob: 83033b137f8dcaef0f85e874b834c64789bb389d (
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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "wordnummapper.h"
#include <vespa/fastlib/io/bufferedfile.h>
#include <cassert>
namespace search::diskindex {
WordNumMapping::WordNumMapping()
: _old2newwords(),
_oldDictSize(0u)
{
}
void
WordNumMapping::readMappingFile(const vespalib::string &name,
const TuneFileSeqRead &tuneFileRead)
{
// Open word mapping file
Fast_BufferedFile old2newwordfile(new FastOS_File);
if (tuneFileRead.getWantDirectIO()) {
old2newwordfile.EnableDirectIO();
}
// XXX no checking for success
old2newwordfile.ReadOpen(name.c_str());
int64_t tempfilesize = old2newwordfile.getSize();
uint64_t tempfileentries = static_cast<uint64_t>(tempfilesize /
sizeof(uint64_t));
Array &map = _old2newwords;
map.resize(tempfileentries + 2);
_oldDictSize = tempfileentries;
ssize_t has_read = old2newwordfile.Read(&map[1], static_cast<size_t>(tempfilesize));
assert(has_read == tempfilesize);
map[0] = noWordNum();
map[tempfileentries + 1] = noWordNumHigh();
}
void
WordNumMapping::noMappingFile()
{
Array &map = _old2newwords;
map.resize(2);
map[0] = noWordNum();
map[1] = noWordNumHigh();
_oldDictSize = 0;
}
void
WordNumMapping::clear()
{
Array &map = _old2newwords;
map.clear();
_oldDictSize = 0;
}
void
WordNumMapping::setup(uint32_t numWordIds)
{
_oldDictSize = numWordIds;
}
}
|