am b6764c51: Merge "Fix: terminal lookup table flushing."
* commit 'b6764c51ab6acc8b5acf3ce3513e30c9ce82d02c': Fix: terminal lookup table flushing.main
commit
3d6cd9c9d9
|
@ -25,7 +25,7 @@ const BigramEntry BigramDictContent::getBigramEntryAndAdvancePosition(
|
||||||
const BufferWithExtendableBuffer *const bigramListBuffer = getContentBuffer();
|
const BufferWithExtendableBuffer *const bigramListBuffer = getContentBuffer();
|
||||||
const int bigramFlags = bigramListBuffer->readUintAndAdvancePosition(
|
const int bigramFlags = bigramListBuffer->readUintAndAdvancePosition(
|
||||||
Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, bigramEntryPos);
|
Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, bigramEntryPos);
|
||||||
const int hasNext = (bigramFlags & Ver4DictConstants::BIGRAM_HAS_NEXT_MASK) != 0;
|
const bool hasNext = (bigramFlags & Ver4DictConstants::BIGRAM_HAS_NEXT_MASK) != 0;
|
||||||
int probability = NOT_A_PROBABILITY;
|
int probability = NOT_A_PROBABILITY;
|
||||||
int timestamp = Ver4DictConstants::NOT_A_TIME_STAMP;
|
int timestamp = Ver4DictConstants::NOT_A_TIME_STAMP;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
|
|
@ -53,13 +53,12 @@ bool TerminalPositionLookupTable::setTerminalPtNodePosition(
|
||||||
bool TerminalPositionLookupTable::flushToFile(const char *const dictDirPath,
|
bool TerminalPositionLookupTable::flushToFile(const char *const dictDirPath,
|
||||||
const int newHeaderRegionSize) const {
|
const int newHeaderRegionSize) const {
|
||||||
const int headerRegionSizeDiff = newHeaderRegionSize - mHeaderRegionSize;
|
const int headerRegionSizeDiff = newHeaderRegionSize - mHeaderRegionSize;
|
||||||
// If header region size has been changed, terminal PtNode positions have to be adjusted
|
// If header region size has been changed or used buffer size is smaller than actual buffer
|
||||||
// depending on the new header region size.
|
// size, regenerate lookup table and write the new table to file.
|
||||||
if (headerRegionSizeDiff != 0) {
|
if (headerRegionSizeDiff != 0 || getEntryPos(mSize) < getBuffer()->getTailPosition()) {
|
||||||
TerminalPositionLookupTable lookupTableToWrite;
|
TerminalPositionLookupTable lookupTableToWrite(newHeaderRegionSize);
|
||||||
for (int i = 0; i < mSize; ++i) {
|
for (int i = 0; i < mSize; ++i) {
|
||||||
const int terminalPtNodePosition = getTerminalPtNodePosition(i)
|
const int terminalPtNodePosition = getTerminalPtNodePosition(i);
|
||||||
+ headerRegionSizeDiff;
|
|
||||||
if (!lookupTableToWrite.setTerminalPtNodePosition(i, terminalPtNodePosition)) {
|
if (!lookupTableToWrite.setTerminalPtNodePosition(i, terminalPtNodePosition)) {
|
||||||
AKLOGE("Cannot set terminal position to lookupTableToWrite."
|
AKLOGE("Cannot set terminal position to lookupTableToWrite."
|
||||||
" terminalId: %d, position: %d", i, terminalPtNodePosition);
|
" terminalId: %d, position: %d", i, terminalPtNodePosition);
|
||||||
|
|
|
@ -37,6 +37,9 @@ class TerminalPositionLookupTable : public SingleDictContent {
|
||||||
/ Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE),
|
/ Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE),
|
||||||
mHeaderRegionSize(headerRegionSize) {}
|
mHeaderRegionSize(headerRegionSize) {}
|
||||||
|
|
||||||
|
explicit TerminalPositionLookupTable(const int headerRegionSize)
|
||||||
|
: mSize(0), mHeaderRegionSize(headerRegionSize) {}
|
||||||
|
|
||||||
TerminalPositionLookupTable() : mSize(0), mHeaderRegionSize(0) {}
|
TerminalPositionLookupTable() : mSize(0), mHeaderRegionSize(0) {}
|
||||||
|
|
||||||
int getTerminalPtNodePosition(const int terminalId) const;
|
int getTerminalPtNodePosition(const int terminalId) const;
|
||||||
|
|
Loading…
Reference in New Issue