Fix: ver4 bigram GC.

Bug: 11073222
Change-Id: I1637525ead60026cdf75ac90d40f97d02ce44ea1
main
Keisuke Kuroyanagi 2013-12-02 16:11:25 +09:00
parent 5c48f1970a
commit 11765ee804
1 changed files with 19 additions and 0 deletions

View File

@ -46,6 +46,7 @@ bool BigramDictContent::writeBigramEntryAndAdvancePosition(const int probability
const int bigramFlags = createAndGetBigramFlags(probability, hasNext); const int bigramFlags = createAndGetBigramFlags(probability, hasNext);
if (!bigramListBuffer->writeUintAndAdvancePosition(bigramFlags, if (!bigramListBuffer->writeUintAndAdvancePosition(bigramFlags,
Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, entryWritingPos)) { Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, entryWritingPos)) {
AKLOGE("Cannot write bigram flags. pos: %d, flags: %x", *entryWritingPos, bigramFlags);
return false; return false;
} }
const int targetTerminalIdToWrite = const int targetTerminalIdToWrite =
@ -66,6 +67,7 @@ bool BigramDictContent::copyBigramList(const int bigramListPos, const int toPos)
&readingPos); &readingPos);
if (!writeBigramEntryAndAdvancePosition(probability, hasNext, targetTerminalId, if (!writeBigramEntryAndAdvancePosition(probability, hasNext, targetTerminalId,
&writingPos)) { &writingPos)) {
AKLOGE("Cannot write bigram entry to copy. pos: %d", writingPos);
return false; return false;
} }
} }
@ -88,6 +90,8 @@ bool BigramDictContent::runGC(const TerminalPositionLookupTable::TerminalIdMap *
// Copy bigram list with GC from original content. // Copy bigram list with GC from original content.
if (!runGCBigramList(originalBigramListPos, originalBigramDictContent, bigramListPos, if (!runGCBigramList(originalBigramListPos, originalBigramDictContent, bigramListPos,
terminalIdMap, &bigramEntryCount)) { terminalIdMap, &bigramEntryCount)) {
AKLOGE("Cannot complete GC for the bigram list. original pos: %d, pos: %d",
originalBigramListPos, bigramListPos);
return false; return false;
} }
if (bigramEntryCount == 0) { if (bigramEntryCount == 0) {
@ -97,6 +101,8 @@ bool BigramDictContent::runGC(const TerminalPositionLookupTable::TerminalIdMap *
*outBigramEntryCount += bigramEntryCount; *outBigramEntryCount += bigramEntryCount;
// Set bigram list position to the lookup table. // Set bigram list position to the lookup table.
if (!getUpdatableAddressLookupTable()->set(it->second, bigramListPos)) { if (!getUpdatableAddressLookupTable()->set(it->second, bigramListPos)) {
AKLOGE("Cannot set bigram list position. terminal id: %d, pos: %d",
it->second, bigramListPos);
return false; return false;
} }
} }
@ -111,6 +117,7 @@ bool BigramDictContent::runGCBigramList(const int bigramListPos,
bool hasNext = true; bool hasNext = true;
int readingPos = bigramListPos; int readingPos = bigramListPos;
int writingPos = toPos; int writingPos = toPos;
int lastEntryPos = NOT_A_DICT_POS;
while (hasNext) { while (hasNext) {
int probability = NOT_A_PROBABILITY; int probability = NOT_A_PROBABILITY;
int targetTerminalId = Ver4DictConstants::NOT_A_TERMINAL_ID; int targetTerminalId = Ver4DictConstants::NOT_A_TERMINAL_ID;
@ -125,12 +132,24 @@ bool BigramDictContent::runGCBigramList(const int bigramListPos,
// Target word has been removed. // Target word has been removed.
continue; continue;
} }
lastEntryPos = hasNext ? writingPos : NOT_A_DICT_POS;
if (!writeBigramEntryAndAdvancePosition(probability, hasNext, it->second, if (!writeBigramEntryAndAdvancePosition(probability, hasNext, it->second,
&writingPos)) { &writingPos)) {
AKLOGE("Cannot write bigram entry to run GC. pos: %d", writingPos);
return false; return false;
} }
*outEntrycount += 1; *outEntrycount += 1;
} }
if (lastEntryPos != NOT_A_DICT_POS) {
// Update has next flag in the last written entry.
int probability = NOT_A_PROBABILITY;
int targetTerminalId = Ver4DictConstants::NOT_A_TERMINAL_ID;
getBigramEntry(&probability, 0 /* outHasNext */, &targetTerminalId, lastEntryPos);
if (!writeBigramEntry(probability, false /* hasNext */, targetTerminalId, writingPos)) {
AKLOGE("Cannot write bigram entry to set hasNext flag after GC. pos: %d", writingPos);
return false;
}
}
return true; return true;
} }