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.
main
Keisuke Kuroynagi 2013-06-26 21:00:24 -07:00 committed by Android Git Automerger
commit 12c6ed411a
3 changed files with 13 additions and 16 deletions

View File

@ -270,6 +270,7 @@ static inline void prof_out(void) {
#define NOT_A_COORDINATE (-1) #define NOT_A_COORDINATE (-1)
#define NOT_AN_INDEX (-1) #define NOT_AN_INDEX (-1)
#define NOT_A_PROBABILITY (-1) #define NOT_A_PROBABILITY (-1)
#define NOT_A_DICT_POS (S_INT_MIN)
#define KEYCODE_SPACE ' ' #define KEYCODE_SPACE ' '
#define KEYCODE_SINGLE_QUOTE '\'' #define KEYCODE_SINGLE_QUOTE '\''

View File

@ -97,7 +97,6 @@ class DicNode {
DicNode &operator=(const DicNode &dicNode); DicNode &operator=(const DicNode &dicNode);
virtual ~DicNode() {} virtual ~DicNode() {}
// TODO: minimize arguments by looking binary_format
// Init for copy // Init for copy
void initByCopy(const DicNode *dicNode) { void initByCopy(const DicNode *dicNode) {
mIsUsed = true; mIsUsed = true;
@ -107,13 +106,12 @@ class DicNode {
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
} }
// TODO: minimize arguments by looking binary_format
// Init for root with prevWordNodePos which is used for bigram // 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; mIsUsed = true;
mIsCachedForNextSuggestion = false; mIsCachedForNextSuggestion = false;
mDicNodeProperties.init( 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 */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */,
false /* isTerminal */, true /* hasChildren */, 0 /* depth */, false /* isTerminal */, true /* hasChildren */, 0 /* depth */,
0 /* terminalDepth */); 0 /* terminalDepth */);
@ -130,13 +128,12 @@ class DicNode {
PROF_NODE_COPY(&parentNode->mProfiler, mProfiler); PROF_NODE_COPY(&parentNode->mProfiler, mProfiler);
} }
// TODO: minimize arguments by looking binary_format
// Init for root with previous word // 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; mIsUsed = true;
mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion; mIsCachedForNextSuggestion = dicNode->mIsCachedForNextSuggestion;
mDicNodeProperties.init( 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 */, NOT_A_CODE_POINT /* nodeCodePoint */, NOT_A_PROBABILITY /* probability */,
false /* isTerminal */, true /* hasChildren */, 0 /* depth */, false /* isTerminal */, true /* hasChildren */, 0 /* depth */,
0 /* terminalDepth */); 0 /* terminalDepth */);

View File

@ -36,17 +36,14 @@ namespace latinime {
/* static */ void DicNodeUtils::initAsRoot(const BinaryDictionaryInfo *const binaryDictionaryInfo, /* static */ void DicNodeUtils::initAsRoot(const BinaryDictionaryInfo *const binaryDictionaryInfo,
const int prevWordNodePos, DicNode *const newRootNode) { const int prevWordNodePos, DicNode *const newRootNode) {
const int rootPos = binaryDictionaryInfo->getRootPosition(); newRootNode->initAsRoot(binaryDictionaryInfo->getRootPosition(), prevWordNodePos);
const int childrenPos = rootPos;
newRootNode->initAsRoot(rootPos, childrenPos, prevWordNodePos);
} }
/*static */ void DicNodeUtils::initAsRootWithPreviousWord( /*static */ void DicNodeUtils::initAsRootWithPreviousWord(
const BinaryDictionaryInfo *const binaryDictionaryInfo, const BinaryDictionaryInfo *const binaryDictionaryInfo,
DicNode *const prevWordLastNode, DicNode *const newRootNode) { DicNode *const prevWordLastNode, DicNode *const newRootNode) {
const int rootPos = binaryDictionaryInfo->getRootPosition(); newRootNode->initAsRootWithPreviousWord(
const int childrenPos = rootPos; prevWordLastNode, binaryDictionaryInfo->getRootPosition());
newRootNode->initAsRootWithPreviousWord(prevWordLastNode, rootPos, childrenPos);
} }
/* static */ void DicNodeUtils::initByCopy(DicNode *srcNode, DicNode *destNode) { /* 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 hasMultipleChars = (0 != (BinaryFormat::FLAG_HAS_MULTIPLE_CHARS & flags));
const bool isTerminal = (0 != (BinaryFormat::FLAG_IS_TERMINAL & flags)); const bool isTerminal = (0 != (BinaryFormat::FLAG_IS_TERMINAL & flags));
const bool hasChildren = BinaryFormat::hasChildrenInFlags(flags); const bool hasChildren = BinaryFormat::hasChildrenInFlags(flags);
const bool hasShortcuts = (0 != (BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS & flags));
int codePoint = BinaryFormat::getCodePointAndForwardPointer( int codePoint = BinaryFormat::getCodePointAndForwardPointer(
binaryDictionaryInfo->getDictRoot(), &pos); binaryDictionaryInfo->getDictRoot(), &pos);
@ -101,11 +99,12 @@ namespace latinime {
} while (NOT_A_CODE_POINT != codePoint); } while (NOT_A_CODE_POINT != codePoint);
const int probability = isTerminal ? BinaryFormat::readProbabilityWithoutMovingPointer( const int probability = isTerminal ? BinaryFormat::readProbabilityWithoutMovingPointer(
binaryDictionaryInfo->getDictRoot(), pos) : -1; binaryDictionaryInfo->getDictRoot(), pos) : NOT_A_PROBABILITY;
pos = BinaryFormat::skipProbability(flags, pos); pos = BinaryFormat::skipProbability(flags, pos);
int childrenPos = hasChildren ? BinaryFormat::readChildrenPosition( int childrenPos = hasChildren ? BinaryFormat::readChildrenPosition(
binaryDictionaryInfo->getDictRoot(), flags, pos) : 0; binaryDictionaryInfo->getDictRoot(), flags, pos) : NOT_A_DICT_POS;
const int attributesPos = BinaryFormat::skipChildrenPosition(flags, pos); const int attributesPos =
hasShortcuts ? BinaryFormat::skipChildrenPosition(flags, pos) : NOT_A_DICT_POS;
const int siblingPos = BinaryFormat::skipChildrenPosAndAttributes( const int siblingPos = BinaryFormat::skipChildrenPosAndAttributes(
binaryDictionaryInfo->getDictRoot(), flags, pos); binaryDictionaryInfo->getDictRoot(), flags, pos);