MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / BuildMatcher

Function BuildMatcher

src/PrefixMatch.cpp:302–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302std::unique_ptr<PrefixMatch::Tables::Matcher> BuildMatcher(
303 const DictPtr& dict) {
304 const std::list<DictPtr>* dictGroupItems = dict->GetDictGroupItems();
305 if (dictGroupItems != nullptr) {
306 // If the entire subtree is a pure union of leaf dicts, merge all entries
307 // into a single LeafMatcher. One trie traversal finds the longest match
308 // across all dicts, which equals union semantics, and eliminates the
309 // overhead of GroupMatcher dispatch and multiple traversals.
310 if (CanFlattenAsUnion(dict)) {
311 std::unique_ptr<LeafMatcher> leaf(new LeafMatcher);
312 CollectAllLeafDicts(dict, leaf.get());
313 return std::move(leaf);
314 }
315
316 std::unique_ptr<GroupMatcher> group(
317 new GroupMatcher(dict->GetMatchPolicy()));
318 for (const DictPtr& child : *dictGroupItems) {
319 group->AddChild(BuildMatcher(child));
320 }
321 return std::move(group);
322 }
323
324 std::unique_ptr<LeafMatcher> leaf(new LeafMatcher);
325 leaf->AddDict(dict);
326 return std::move(leaf);
327}
328
329PrefixMatch::PrefixMatch(const DictPtr& dict) {
330 // Try to unwrap single dict group

Callers 1

PrefixMatchMethod · 0.85

Calls 6

CanFlattenAsUnionFunction · 0.85
CollectAllLeafDictsFunction · 0.85
moveFunction · 0.85
AddChildMethod · 0.80
AddDictMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected