-
Notifications
You must be signed in to change notification settings - Fork 4
/
common_container.cc
65 lines (56 loc) · 1.7 KB
/
common_container.cc
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
#include "common_container.h"
#include <algorithm>
#include <sstream>
#include "fmt/format.h"
namespace component {
bool CommonContainer::IndexingToken(const FieldMeta* meta,
const EntryId eid,
const Token* token) {
if (token->BadToken()) {
return false;
}
for (int64_t value : token->Int64()) {
Attr attr = {meta->name, value};
values_[attr].push_back(eid);
}
return true;
}
EntriesList CommonContainer::RetrieveEntries(const FieldMeta* meta,
const Token* token) const {
EntriesList results;
for (int64_t value : token->Int64()) {
Attr attr(meta->name, value);
auto iter = values_.find(attr);
if (iter == values_.end()) {
continue;
}
results.push_back(&(iter->second));
}
return results;
}
bool CommonContainer::CompileEntries() {
for (auto& pair : values_) {
sum_len_ += pair.second.size();
if (max_len_ < pair.second.size()) {
max_len_ = pair.second.size();
}
std::sort(pair.second.begin(), pair.second.end());
}
return true;
};
void CommonContainer::DumpEntries(std::ostringstream& oss) const {
oss << "+++++ start dump common container entries ++++++++++\n";
for (auto& kvs : values_) {
oss << "<" << kvs.first.first << "," << kvs.first.second << ">:";
// fmt::format("{}", fmt::join(kvs.second, ","));
for (auto iter = kvs.second.begin(); iter != kvs.second.end(); iter++) {
if (iter != kvs.second.begin()) {
oss << ",";
}
oss << EntryUtil::ToString(*iter);
}
oss << "\n";
}
oss << "++++++++++++++++ end all entries +++++++++++++++++++\n";
}
} // end namespace component