2014-01-16 23:07:42 +01:00
|
|
|
#ifndef word_db_hh_INCLUDED
|
|
|
|
#define word_db_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
2015-01-15 14:54:38 +01:00
|
|
|
#include "shared_string.hh"
|
2015-01-07 20:29:31 +01:00
|
|
|
#include "unordered_map.hh"
|
|
|
|
#include "vector.hh"
|
2015-10-22 20:49:08 +02:00
|
|
|
#include "ranked_match.hh"
|
2014-01-16 23:07:42 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-01-28 21:29:10 +01:00
|
|
|
using RankedMatchList = Vector<RankedMatch>;
|
|
|
|
|
2014-01-16 23:07:42 +01:00
|
|
|
// maintain a database of words available in a buffer
|
2016-08-21 21:25:11 +02:00
|
|
|
class WordDB : public OptionManagerWatcher
|
2014-01-16 23:07:42 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WordDB(const Buffer& buffer);
|
2016-08-21 21:25:11 +02:00
|
|
|
~WordDB();
|
2014-12-22 21:08:53 +01:00
|
|
|
WordDB(const WordDB&) = delete;
|
2016-08-21 21:25:11 +02:00
|
|
|
WordDB(WordDB&&);
|
2014-01-16 23:07:42 +01:00
|
|
|
|
2015-10-22 20:49:08 +02:00
|
|
|
RankedMatchList find_matching(StringView str);
|
2015-10-18 17:55:21 +02:00
|
|
|
|
2014-10-01 01:20:12 +02:00
|
|
|
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();
|
2016-02-05 10:36:07 +01:00
|
|
|
void add_words(StringView line);
|
|
|
|
void remove_words(StringView line);
|
2014-01-16 23:07:42 +01:00
|
|
|
|
2016-08-21 21:25:11 +02:00
|
|
|
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;
|
|
|
|
};
|
2016-02-05 10:36:07 +01:00
|
|
|
using WordToInfo = UnorderedMap<StringView, WordInfo, MemoryDomain::WordDB>;
|
2015-03-01 13:06:19 +01:00
|
|
|
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
|
2014-01-16 23:07:42 +01:00
|
|
|
|
2015-02-19 14:58:25 +01:00
|
|
|
SafePtr<const Buffer> m_buffer;
|
2014-05-14 22:19:19 +02:00
|
|
|
size_t m_timestamp;
|
2014-12-23 20:32:42 +01:00
|
|
|
WordToInfo m_words;
|
2015-01-15 14:58:55 +01:00
|
|
|
Lines m_lines;
|
2014-01-16 23:07:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // word_db_hh_INCLUDED
|