home/src/word_db.hh

57 lines
1.2 KiB
C++
Raw Normal View History

#ifndef word_db_hh_INCLUDED
#define word_db_hh_INCLUDED
#include "buffer.hh"
#include "shared_string.hh"
#include "unordered_map.hh"
#include "vector.hh"
2014-10-28 20:23:02 +01:00
#include <bitset>
namespace Kakoune
{
2014-12-23 20:32:42 +01:00
using UsedLetters = std::bitset<64>;
UsedLetters used_letters(StringView str);
// maintain a database of words available in a buffer
class WordDB
{
public:
WordDB(const Buffer& buffer);
2014-12-22 21:08:53 +01:00
WordDB(const WordDB&) = delete;
2014-10-28 20:23:02 +01:00
WordDB(WordDB&&) = default;
struct RankedWord
{
StringView word;
int rank;
};
using RankedWordList = Vector<RankedWord>;
RankedWordList 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();
2015-03-10 14:50:25 +01:00
void add_words(const SharedString& line);
void remove_words(const SharedString& line);
2014-10-28 20:23:02 +01:00
struct WordInfo
{
2014-12-23 20:32:42 +01:00
UsedLetters letters;
2014-10-28 20:23:02 +01:00
int refcount;
};
using WordToInfo = UnorderedMap<SharedString, 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;
};
}
#endif // word_db_hh_INCLUDED