diff options
author | 2013-12-09 13:05:44 +0900 | |
---|---|---|
committer | 2013-12-09 13:05:44 +0900 | |
commit | 5f88c1e0f1882e9677fb316587b51c31e49b804c (patch) | |
tree | 4eb2aa701a7fa07eb2c52651ed5321384c0eae31 /native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp | |
parent | a2bbb1213d41019b23b3df63dbfcaecdd0694ff6 (diff) | |
download | latinime-5f88c1e0f1882e9677fb316587b51c31e49b804c.tar.gz latinime-5f88c1e0f1882e9677fb316587b51c31e49b804c.tar.xz latinime-5f88c1e0f1882e9677fb316587b51c31e49b804c.zip |
Start to support adding shortcuts.
Bug: 11073222
Bug: 11956652
Change-Id: Iea81603a140697594cfea4f4939e82cd1d3963ca
Diffstat (limited to 'native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp')
-rw-r--r-- | native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp index 9be35620c..4ad82f9f7 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.cpp @@ -44,6 +44,7 @@ bool SparseTable::set(const int id, const uint32_t value) { int tailPos = mIndexTableBuffer->getTailPosition(); while(tailPos < posInIndexTable) { if (!mIndexTableBuffer->writeUintAndAdvancePosition(NOT_EXIST, INDEX_SIZE, &tailPos)) { + AKLOGE("cannot extend index table. tailPos: %d to: %d", tailPos, posInIndexTable); return false; } } @@ -51,12 +52,19 @@ bool SparseTable::set(const int id, const uint32_t value) { if (contains(id)) { // The entry is already in the content table. const int index = mIndexTableBuffer->readUint(INDEX_SIZE, posInIndexTable); - return mContentTableBuffer->writeUint(value, mDataSize, getPosInContentTable(id, index)); + if (!mContentTableBuffer->writeUint(value, mDataSize, getPosInContentTable(id, index))) { + AKLOGE("cannot update value %d. pos: %d, tailPos: %d, mDataSize: %d", value, + getPosInContentTable(id, index), mContentTableBuffer->getTailPosition(), + mDataSize); + return false; + } + return true; } // The entry is not in the content table. // Create new entry in the content table. const int index = getIndexFromContentTablePos(mContentTableBuffer->getTailPosition()); if (!mIndexTableBuffer->writeUint(index, INDEX_SIZE, posInIndexTable)) { + AKLOGE("cannot write index %d. pos %d", index, posInIndexTable); return false; } // Write a new block that containing the entry to be set. @@ -64,6 +72,8 @@ bool SparseTable::set(const int id, const uint32_t value) { for (int i = 0; i < mBlockSize; ++i) { if (!mContentTableBuffer->writeUintAndAdvancePosition(NOT_A_DICT_POS, mDataSize, &writingPos)) { + AKLOGE("cannot write content table to extend. writingPos: %d, tailPos: %d, " + "mDataSize: %d", writingPos, mContentTableBuffer->getTailPosition(), mDataSize); return false; } } @@ -80,7 +90,7 @@ int SparseTable::getPosInIndexTable(const int id) const { int SparseTable::getPosInContentTable(const int id, const int index) const { const int offset = id % mBlockSize; - return (index * mDataSize + offset) * mBlockSize; + return (index * mBlockSize + offset) * mDataSize; } } // namespace latinime |