11 #include <type_traits> 12 #include <unordered_set> 13 #include <fcitx-utils/macros.h> 14 #include "lattice_p.h" 15 #include "segmentgraph.h" 19 WordNode::WordNode(WordNode &&other) noexcept(
20 std::is_nothrow_move_constructible<std::string>::value) =
default;
21 WordNode &WordNode::operator=(WordNode &&other) noexcept(
22 std::is_nothrow_move_assignable<std::string>::value) =
default;
24 Lattice::Lattice() : d_ptr(std::make_unique<LatticePrivate>()) {}
26 FCITX_DEFINE_DEFAULT_DTOR_AND_MOVE(Lattice)
28 size_t Lattice::sentenceSize()
const {
30 return d->nbests_.size();
33 const SentenceResult &Lattice::sentence(
size_t idx)
const {
35 return d->nbests_[idx];
38 Lattice::NodeRange Lattice::nodes(
const SegmentGraphNode *node)
const {
40 auto iter = d->lattice_.find(node);
41 if (iter == d->lattice_.end()) {
44 return {iter->second.begin(), iter->second.end()};
47 void Lattice::clear() {
53 void Lattice::discardNode(
54 const std::unordered_set<const SegmentGraphNode *> &nodes) {
56 for (
const auto *node : nodes) {
57 d->lattice_.erase(node);
59 for (
auto &p : d->lattice_) {
60 p.second.erase_if([&nodes](
const LatticeNode &node) {
61 return nodes.count(node.from());