mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-21 10:40:53 +03:00
bc11e52960
We should never destruct anything through an OptionManagerWatcher pointer, so having all those destructor virtual makes no sense.
54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
#ifndef word_db_hh_INCLUDED
|
|
#define word_db_hh_INCLUDED
|
|
|
|
#include "buffer.hh"
|
|
#include "shared_string.hh"
|
|
#include "hash_map.hh"
|
|
#include "vector.hh"
|
|
#include "ranked_match.hh"
|
|
|
|
namespace Kakoune
|
|
{
|
|
|
|
using RankedMatchList = Vector<RankedMatch>;
|
|
|
|
// maintain a database of words available in a buffer
|
|
class WordDB : public OptionManagerWatcher
|
|
{
|
|
public:
|
|
WordDB(const Buffer& buffer);
|
|
~WordDB();
|
|
WordDB(const WordDB&) = delete;
|
|
WordDB(WordDB&&) noexcept;
|
|
|
|
RankedMatchList find_matching(StringView str);
|
|
|
|
int get_word_occurences(StringView word) const;
|
|
private:
|
|
void update_db();
|
|
void add_words(StringView line);
|
|
void remove_words(StringView line);
|
|
|
|
void rebuild_db();
|
|
|
|
void on_option_changed(const Option& option) override;
|
|
|
|
struct WordInfo
|
|
{
|
|
StringDataPtr word;
|
|
UsedLetters letters;
|
|
int refcount;
|
|
};
|
|
using WordToInfo = HashMap<StringView, WordInfo, MemoryDomain::WordDB>;
|
|
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
|
|
|
|
SafePtr<const Buffer> m_buffer;
|
|
size_t m_timestamp;
|
|
WordToInfo m_words;
|
|
Lines m_lines;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // word_db_hh_INCLUDED
|