kakoune/src/word_db.hh

58 lines
1.3 KiB
C++
Raw Normal View History

#ifndef word_db_hh_INCLUDED
#define word_db_hh_INCLUDED
#include "shared_string.hh"
#include "hash_map.hh"
#include "vector.hh"
#include "ranked_match.hh"
2019-01-24 11:02:07 +01:00
#include "option_manager.hh"
#include "safe_ptr.hh"
namespace Kakoune
{
2016-01-28 21:29:10 +01:00
using RankedMatchList = Vector<RankedMatch>;
2019-01-24 11:02:07 +01:00
class Buffer;
2016-01-28 21:29:10 +01:00
// maintain a database of words available in a buffer
class WordDB : public OptionManagerWatcher
{
public:
WordDB(const Buffer& buffer);
~WordDB();
2014-12-22 21:08:53 +01:00
WordDB(const WordDB&) = delete;
WordDB(WordDB&&) noexcept;
RankedMatchList find_matching(StringView str);
int get_word_occurences(StringView word) const;
2015-01-12 14:58:41 +01:00
private:
2015-01-13 14:57:44 +01:00
void update_db();
void add_words(StringView line, ConstArrayView<Codepoint> extra_word_chars);
void remove_words(StringView line, ConstArrayView<Codepoint> extra_word_chars);
void rebuild_db();
void on_option_changed(const Option& option) override;
2014-10-28 20:23:02 +01:00
struct WordInfo
{
2016-02-05 10:36:07 +01:00
StringDataPtr word;
2014-12-23 20:32:42 +01:00
UsedLetters letters;
2014-10-28 20:23:02 +01: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 20:32:42 +01:00
WordToInfo m_words;
Lines m_lines;
};
2018-04-15 05:21:57 +02:00
WordDB& get_word_db(const Buffer& buffer);
}
#endif // word_db_hh_INCLUDED