2014-01-17 02:07:42 +04:00
|
|
|
#ifndef word_db_hh_INCLUDED
|
|
|
|
#define word_db_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
2015-01-15 16:54:38 +03:00
|
|
|
#include "shared_string.hh"
|
2015-01-07 22:29:31 +03:00
|
|
|
#include "unordered_map.hh"
|
|
|
|
#include "vector.hh"
|
2014-01-17 02:07:42 +04:00
|
|
|
|
2014-10-28 22:23:02 +03:00
|
|
|
#include <bitset>
|
2014-01-17 02:07:42 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-12-23 22:32:42 +03:00
|
|
|
using UsedLetters = std::bitset<64>;
|
|
|
|
UsedLetters used_letters(StringView str);
|
|
|
|
|
2014-01-17 02:07:42 +04:00
|
|
|
// maintain a database of words available in a buffer
|
2014-01-24 04:56:33 +04:00
|
|
|
class WordDB
|
2014-01-17 02:07:42 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WordDB(const Buffer& buffer);
|
2014-12-22 23:08:53 +03:00
|
|
|
WordDB(const WordDB&) = delete;
|
2014-10-28 22:23:02 +03:00
|
|
|
WordDB(WordDB&&) = default;
|
2014-01-17 02:07:42 +04:00
|
|
|
|
2015-10-18 18:55:21 +03:00
|
|
|
struct RankedWord
|
|
|
|
{
|
|
|
|
StringView word;
|
|
|
|
int rank;
|
|
|
|
};
|
|
|
|
using RankedWordList = Vector<RankedWord>;
|
|
|
|
|
|
|
|
RankedWordList find_matching(StringView str);
|
|
|
|
|
2014-10-01 03:20:12 +04:00
|
|
|
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();
|
2015-03-10 16:50:25 +03:00
|
|
|
void add_words(const SharedString& line);
|
|
|
|
void remove_words(const SharedString& line);
|
2014-01-17 02:07:42 +04:00
|
|
|
|
2014-10-28 22:23:02 +03:00
|
|
|
struct WordInfo
|
|
|
|
{
|
2014-12-23 22:32:42 +03:00
|
|
|
UsedLetters letters;
|
2014-10-28 22:23:02 +03:00
|
|
|
int refcount;
|
|
|
|
};
|
2015-01-15 16:54:38 +03:00
|
|
|
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
|
2015-03-01 15:06:19 +03:00
|
|
|
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
|
2014-01-17 02:07:42 +04:00
|
|
|
|
2015-02-19 16:58:25 +03:00
|
|
|
SafePtr<const Buffer> m_buffer;
|
2014-05-15 00:19:19 +04:00
|
|
|
size_t m_timestamp;
|
2014-12-23 22:32:42 +03:00
|
|
|
WordToInfo m_words;
|
2015-01-15 16:58:55 +03:00
|
|
|
Lines m_lines;
|
2014-01-17 02:07:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // word_db_hh_INCLUDED
|