MCPcopy Create free account
hub / github.com/Snapchat/Valdi / fromEntries

Method fromEntries

valdi_core/src/valdi_core/cpp/Utils/ReferenceTable.cpp:16–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14namespace Valdi {
15
16ReferenceTableStats ReferenceTableStats::fromEntries(size_t tableSize,
17 const std::vector<ReferenceTableEntry>& entries) {
18 ReferenceTableStats out;
19 out.tableSize = tableSize;
20 out.activeReferencesCount = entries.size();
21
22 Valdi::FlatMap<const char*, size_t> activeReferencesByTag;
23
24 for (const auto& entry : entries) {
25 auto it = activeReferencesByTag.find(entry.tag);
26 if (it == activeReferencesByTag.end()) {
27 activeReferencesByTag[entry.tag] = 1;
28 } else {
29 it->second++;
30 }
31 }
32
33 for (const auto& it : activeReferencesByTag) {
34 out.activeReferencesByTag.emplace_back(it);
35 }
36
37 std::sort(out.activeReferencesByTag.begin(),
38 out.activeReferencesByTag.end(),
39 [](const std::pair<const char*, size_t>& left, const std::pair<const char*, size_t>& right) -> bool {
40 return left.second > right.second;
41 });
42
43 return out;
44}
45
46static void handleFatalError(const std::string& message) {
47 SC_ABORT(message);

Callers 1

Calls 4

endMethod · 0.65
sizeMethod · 0.45
findMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected