1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-30 15:13:30 +03:00
kakoune/src/word_db.hh

54 lines
1.1 KiB
C++
Raw Normal View History

#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
{
2016-01-28 23:29:10 +03:00
using RankedMatchList = Vector<RankedMatch>;
// maintain a database of words available in a buffer
class WordDB : public OptionManagerWatcher
{
public:
WordDB(const Buffer& buffer);
~WordDB();
2014-12-22 23:08:53 +03:00
WordDB(const WordDB&) = delete;
WordDB(WordDB&&) noexcept;
RankedMatchList find_matching(StringView str);
int get_word_occurences(StringView word) const;
2015-01-12 16:58:41 +03:00
private:
2015-01-13 16:57:44 +03:00
void update_db();
2016-02-05 12:36:07 +03:00
void add_words(StringView line);
void remove_words(StringView line);
void rebuild_db();
void on_option_changed(const Option& option) override;
2014-10-28 22:23:02 +03:00
struct WordInfo
{
2016-02-05 12:36:07 +03:00
StringDataPtr word;
2014-12-23 22:32:42 +03:00
UsedLetters letters;
2014-10-28 22:23:02 +03:00
int refcount;
};
using WordToInfo = HashMap<StringView, WordInfo, MemoryDomain::WordDB>;
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
SafePtr<const Buffer> m_buffer;
size_t m_timestamp;
2014-12-23 22:32:42 +03:00
WordToInfo m_words;
Lines m_lines;
};
}
#endif // word_db_hh_INCLUDED