#ifndef word_db_hh_INCLUDED #define word_db_hh_INCLUDED #include "buffer.hh" #include "interned_string.hh" #include #include namespace Kakoune { using UsedLetters = std::bitset<64>; UsedLetters used_letters(StringView str); // maintain a database of words available in a buffer class WordDB { public: WordDB(const Buffer& buffer); WordDB(const WordDB&) = delete; WordDB(WordDB&&) = default; using WordList = std::vector; template WordList find_matching(StringView str, MatchFunc match) { update_db(); const UsedLetters letters = used_letters(str); std::vector res; for (auto&& word : m_words) { if ((letters & word.second.letters) == letters and match(word.first, str)) res.push_back(word.first); } return res; } int get_word_occurences(StringView word) const; struct WordInfo { UsedLetters letters; int refcount; }; using WordToInfo = UnorderedMap; private: using LineToWords = std::vector; void update_db(); void add_words(const WordList& words); void remove_words(const WordList& words); safe_ptr m_buffer; size_t m_timestamp; WordToInfo m_words; LineToWords m_line_to_words; }; } #endif // word_db_hh_INCLUDED