Refactor: Move utility functions and no suggestion functions from unigram_dictionary.cpp to dictionary.cpp
Change-Id: I6f695e4f5852547d2c00de5ee54a650fef9accbe
diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h
index 28e4308..4cb1abe 100644
--- a/native/src/unigram_dictionary.h
+++ b/native/src/unigram_dictionary.h
@@ -17,33 +17,20 @@
#ifndef LATINIME_UNIGRAM_DICTIONARY_H
#define LATINIME_UNIGRAM_DICTIONARY_H
+#include "defines.h"
+
namespace latinime {
-// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
-#define ADDRESS_MASK 0x3FFFFF
-
-// The bit that decides if an address follows in the next 22 bits
-#define FLAG_ADDRESS_MASK 0x40
-// The bit that decides if this is a terminal node for a word. The node could still have children,
-// if the word has other endings.
-#define FLAG_TERMINAL_MASK 0x80
-
-#define FLAG_BIGRAM_READ 0x80
-#define FLAG_BIGRAM_CHILDEXIST 0x40
-#define FLAG_BIGRAM_CONTINUED 0x80
-#define FLAG_BIGRAM_FREQ 0x7F
-
-class Dictionary;
class UnigramDictionary {
public:
- UnigramDictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier, int maxWordLength,
- int maxWords, int maxAlternatives, Dictionary *parentDictionary);
+ UnigramDictionary(const unsigned char *dict, int typedLetterMultipler, int fullWordMultiplier,
+ int maxWordLength, int maxWords, int maxAlternatives, const bool isLatestDictVersion,
+ const bool hasBigram, Dictionary *parentDictionary);
int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
int *nextLetters, int nextLettersSize);
int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams,
int maxAlternatives);
- bool isValidWord(unsigned short *word, int length);
~UnigramDictionary();
private:
@@ -57,11 +44,9 @@
int getBigramFreq(int *pos);
void searchForTerminalNode(int address, int frequency);
- bool getFirstBitOfByte(int *pos) { return (mDict[*pos] & 0x80) > 0; }
- bool getSecondBitOfByte(int *pos) { return (mDict[*pos] & 0x40) > 0; }
- bool getTerminal(int *pos) { return (mDict[*pos] & FLAG_TERMINAL_MASK) > 0; }
- int getCount(int *pos) { return mDict[(*pos)++] & 0xFF; }
- unsigned short getChar(int *pos);
+ bool getFirstBitOfByte(int *pos) { return (DICT[*pos] & 0x80) > 0; }
+ bool getSecondBitOfByte(int *pos) { return (DICT[*pos] & 0x40) > 0; }
+ bool getTerminal(int *pos) { return (DICT[*pos] & FLAG_TERMINAL_MASK) > 0; }
int wideStrLen(unsigned short *str);
bool sameAsTyped(unsigned short *word, int length);
@@ -72,15 +57,16 @@
void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency,
int inputIndex, int diffs, int skipPos, int *nextLetters, int nextLettersSize);
void registerNextLetter(unsigned short c, int *nextLetters, int nextLettersSize);
- int isValidWordRec(int pos, unsigned short *word, int offset, int length);
- unsigned char *mDict;
- Dictionary *mParentDictionary;
+ const unsigned char *DICT;
const int MAX_WORDS;
const int MAX_WORD_LENGTH;
const int MAX_ALTERNATIVES;
+ const bool IS_LATEST_DICT_VERSION;
+ const bool HAS_BIGRAM;
+ Dictionary *mParentDictionary;
int *mFrequencies;
int *mBigramFreq;
int mMaxBigrams;