am 68e7edfd
: Use NOT_A_DICT_POS instead of 0 to express not valid ditctionary position.
* commit '68e7edfd99cc5b2c72a6a8887cd345011f4625a1': Use NOT_A_DICT_POS instead of 0 to express not valid ditctionary position.
This commit is contained in:
commit
12c6ed411a
3 changed files with 13 additions and 16 deletions
|
@ -270,6 +270,7 @@ static inline void prof_out(void) {
|
|||
#define NOT_A_COORDINATE (-1)
|
||||
#define NOT_AN_INDEX (-1)
|
||||
#define NOT_A_PROBABILITY (-1)
|
||||
#define NOT_A_DICT_POS (S_INT_MIN)
|
||||
|
||||
#define KEYCODE_SPACE ' '
|
||||
#define KEYCODE_SINGLE_QUOTE '\''
|
||||
|
|
|
@ -97,7 +97,6 @@ class DicNode {
|
|||
DicNode &operator=(const DicNode &dicNode);
|
||||
virtual ~DicNode() {}
|
||||
|
||||
// TODO: minimize arguments by looking binary_format
|
||||
// Init for copy
|
||||
void initByCopy(const DicNode *dicNode) {
|
||||
mIsUsed = true;
|
||||
|
@ -107,13 +106,12 @@ class DicNode {
|
|||
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
|
||||
}
|
||||
|
||||
// TODO: minimize arguments by looking binary_format
|
||||
// Init for root with prevWordNodePos which is used for bigram
|
||||
void initAsRoot(const int pos, const int childrenPos, const int prevWordNodePos) {
|
||||
void initAsRoot(const int rootGroupPos, const int prevWordNodePos) {
|
||||
mIsUsed = true;
|
||||
mIsCachedForNextSuggestion = false;
|
||||
mDicNodeProperties.init(
|
||||
pos, 0 /* flags */, childrenPos, 0 /* attributesPos */,
|
||||
NOT_A_DICT_POS, 0 /* flags */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */,
|
||||
NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */,
|
||||
false /* isTerminal */, true /* hasChildren */, 0 /* depth */,
|
||||
0 /* terminalDepth */);
|
||||
|
@ -130,13 +128,12 @@ class DicNode {
|
|||
PROF_NODE_COPY(&parentNode->mProfiler, mProfiler);
|
||||
}
|
||||
|
||||
// TODO: minimize arguments by looking binary_format
|
||||
// Init for root with previous word
|
||||
void initAsRootWithPreviousWord(DicNode *dicNode, const int pos, const int childrenPos) {
|
||||
void initAsRootWithPreviousWord(DicNode *dicNode, const int rootGroupPos) {
|
||||
mIsUsed = true;
|
||||
mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion;
|
||||
mDicNodeProperties.init(
|
||||
pos, 0 /* flags */, childrenPos, 0 /* attributesPos */,
|
||||
NOT_A_DICT_POS, 0 /* flags */, rootGroupPos, NOT_A_DICT_POS /* attributesPos */,
|
||||
NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */,
|
||||
false /* isTerminal */, true /* hasChildren */, 0 /* depth */,
|
||||
0 /* terminalDepth */);
|
||||
|
|
|
@ -36,17 +36,14 @@ namespace latinime {
|
|||
|
||||
/* static */ void DicNodeUtils::initAsRoot(const BinaryDictionaryInfo *const binaryDictionaryInfo,
|
||||
const int prevWordNodePos, DicNode *const newRootNode) {
|
||||
const int rootPos = binaryDictionaryInfo->getRootPosition();
|
||||
const int childrenPos = rootPos;
|
||||
newRootNode->initAsRoot(rootPos, childrenPos, prevWordNodePos);
|
||||
newRootNode->initAsRoot(binaryDictionaryInfo->getRootPosition(), prevWordNodePos);
|
||||
}
|
||||
|
||||
/*static */ void DicNodeUtils::initAsRootWithPreviousWord(
|
||||
const BinaryDictionaryInfo *const binaryDictionaryInfo,
|
||||
DicNode *const prevWordLastNode, DicNode *const newRootNode) {
|
||||
const int rootPos = binaryDictionaryInfo->getRootPosition();
|
||||
const int childrenPos = rootPos;
|
||||
newRootNode->initAsRootWithPreviousWord(prevWordLastNode, rootPos, childrenPos);
|
||||
newRootNode->initAsRootWithPreviousWord(
|
||||
prevWordLastNode, binaryDictionaryInfo->getRootPosition());
|
||||
}
|
||||
|
||||
/* static */ void DicNodeUtils::initByCopy(DicNode *srcNode, DicNode *destNode) {
|
||||
|
@ -80,6 +77,7 @@ namespace latinime {
|
|||
const bool hasMultipleChars = (0 != (BinaryFormat::FLAG_HAS_MULTIPLE_CHARS & flags));
|
||||
const bool isTerminal = (0 != (BinaryFormat::FLAG_IS_TERMINAL & flags));
|
||||
const bool hasChildren = BinaryFormat::hasChildrenInFlags(flags);
|
||||
const bool hasShortcuts = (0 != (BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS & flags));
|
||||
|
||||
int codePoint = BinaryFormat::getCodePointAndForwardPointer(
|
||||
binaryDictionaryInfo->getDictRoot(), &pos);
|
||||
|
@ -101,11 +99,12 @@ namespace latinime {
|
|||
} while (NOT_A_CODE_POINT != codePoint);
|
||||
|
||||
const int probability = isTerminal ? BinaryFormat::readProbabilityWithoutMovingPointer(
|
||||
binaryDictionaryInfo->getDictRoot(), pos) : -1;
|
||||
binaryDictionaryInfo->getDictRoot(), pos) : NOT_A_PROBABILITY;
|
||||
pos = BinaryFormat::skipProbability(flags, pos);
|
||||
int childrenPos = hasChildren ? BinaryFormat::readChildrenPosition(
|
||||
binaryDictionaryInfo->getDictRoot(), flags, pos) : 0;
|
||||
const int attributesPos = BinaryFormat::skipChildrenPosition(flags, pos);
|
||||
binaryDictionaryInfo->getDictRoot(), flags, pos) : NOT_A_DICT_POS;
|
||||
const int attributesPos =
|
||||
hasShortcuts ? BinaryFormat::skipChildrenPosition(flags, pos) : NOT_A_DICT_POS;
|
||||
const int siblingPos = BinaryFormat::skipChildrenPosAndAttributes(
|
||||
binaryDictionaryInfo->getDictRoot(), flags, pos);
|
||||
|
||||
|
|
Loading…
Reference in a new issue