diff options
author | jli119X <jianpingx.li@intel.com> | 2014-04-10 11:17:18 +0800 |
---|---|---|
committer | Xiaokang Qin <xiaokang.qin@intel.com> | 2014-04-30 12:32:36 +0800 |
commit | c76bdf94eab1478bc148b9a38882cb95edaf51e3 (patch) | |
tree | 8c530665a525ab710a30b846135028e90a7cb22a | |
parent | a8ede7d04a239e3e3484431e631f3f685e08b1b9 (diff) | |
download | PinyinIME-c76bdf94eab1478bc148b9a38882cb95edaf51e3.tar.gz |
Using uint32 instead of size_t to parse the Pinyin dictionary
Because size_t is 8 bytes, So we should use uint32 which is 4 bytes to parse the Google
Pinyin dictionary.
Change-Id: I270e8d7fdee5667791a11e36f5de64687d4d0e99
Signed-off-by: jli119X <jianpingx.li@intel.com>
-rw-r--r-- | jni/include/dictdef.h | 4 | ||||
-rw-r--r-- | jni/include/dictlist.h | 4 | ||||
-rw-r--r-- | jni/share/dictlist.cpp | 6 | ||||
-rw-r--r-- | jni/share/dicttrie.cpp | 21 | ||||
-rw-r--r-- | jni/share/ngram.cpp | 4 | ||||
-rw-r--r-- | jni/share/spellingtrie.cpp | 8 |
6 files changed, 23 insertions, 24 deletions
diff --git a/jni/include/dictdef.h b/jni/include/dictdef.h index 3e79d98..5e1d781 100644 --- a/jni/include/dictdef.h +++ b/jni/include/dictdef.h @@ -109,8 +109,8 @@ typedef struct { * A node occupies 16 bytes. so, totallly less than 16 * 500 = 8K */ struct LmaNodeLE0 { - size_t son_1st_off; - size_t homo_idx_buf_off; + uint32 son_1st_off; + uint32 homo_idx_buf_off; uint16 spl_idx; uint16 num_of_son; uint16 num_of_homo; diff --git a/jni/include/dictlist.h b/jni/include/dictlist.h index 5fcc12f..b0eb2d0 100644 --- a/jni/include/dictlist.h +++ b/jni/include/dictlist.h @@ -42,9 +42,9 @@ class DictList { // Starting position of those words whose lengths are i+1, counted in // char16 - size_t start_pos_[kMaxLemmaSize + 1]; + uint32 start_pos_[kMaxLemmaSize + 1]; - size_t start_id_[kMaxLemmaSize + 1]; + uint32 start_id_[kMaxLemmaSize + 1]; int (*cmp_func_[kMaxLemmaSize])(const void *, const void *); diff --git a/jni/share/dictlist.cpp b/jni/share/dictlist.cpp index aa7905c..b6becf1 100644 --- a/jni/share/dictlist.cpp +++ b/jni/share/dictlist.cpp @@ -414,14 +414,14 @@ bool DictList::load_list(FILE *fp) { initialized_ = false; - if (fread(&scis_num_, sizeof(size_t), 1, fp) != 1) + if (fread(&scis_num_, sizeof(uint32), 1, fp) != 1) return false; - if (fread(start_pos_, sizeof(size_t), kMaxLemmaSize + 1, fp) != + if (fread(start_pos_, sizeof(uint32), kMaxLemmaSize + 1, fp) != kMaxLemmaSize + 1) return false; - if (fread(start_id_, sizeof(size_t), kMaxLemmaSize + 1, fp) != + if (fread(start_id_, sizeof(uint32), kMaxLemmaSize + 1, fp) != kMaxLemmaSize + 1) return false; diff --git a/jni/share/dicttrie.cpp b/jni/share/dicttrie.cpp index 88b819d..6255f83 100644 --- a/jni/share/dicttrie.cpp +++ b/jni/share/dicttrie.cpp @@ -113,16 +113,16 @@ bool DictTrie::save_dict(FILE *fp) { if (NULL == fp) return false; - if (fwrite(&lma_node_num_le0_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&lma_node_num_le0_, sizeof(uint32), 1, fp) != 1) return false; - if (fwrite(&lma_node_num_ge1_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&lma_node_num_ge1_, sizeof(uint32), 1, fp) != 1) return false; - if (fwrite(&lma_idx_buf_len_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&lma_idx_buf_len_, sizeof(uint32), 1, fp) != 1) return false; - if (fwrite(&top_lmas_num_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&top_lmas_num_, sizeof(uint32), 1, fp) != 1) return false; if (fwrite(root_, sizeof(LmaNodeLE0), lma_node_num_le0_, fp) @@ -168,19 +168,18 @@ bool DictTrie::save_dict(const char *filename) { bool DictTrie::load_dict(FILE *fp) { if (NULL == fp) return false; - - if (fread(&lma_node_num_le0_, sizeof(size_t), 1, fp) != 1) + if (fread(&lma_node_num_le0_, sizeof(uint32), 1, fp) != 1) return false; - if (fread(&lma_node_num_ge1_, sizeof(size_t), 1, fp) != 1) + if (fread(&lma_node_num_ge1_, sizeof(uint32), 1, fp) != 1) return false; - if (fread(&lma_idx_buf_len_, sizeof(size_t), 1, fp) != 1) + if (fread(&lma_idx_buf_len_, sizeof(uint32), 1, fp) != 1) return false; - if (fread(&top_lmas_num_, sizeof(size_t), 1, fp) != 1 || - top_lmas_num_ >= lma_idx_buf_len_) - return false; + if (fread(&top_lmas_num_, sizeof(uint32), 1, fp) != 1 || + top_lmas_num_ >= lma_idx_buf_len_) + return false; free_resource(false); diff --git a/jni/share/ngram.cpp b/jni/share/ngram.cpp index 104b853..6aec850 100644 --- a/jni/share/ngram.cpp +++ b/jni/share/ngram.cpp @@ -164,7 +164,7 @@ bool NGram::save_ngram(FILE *fp) { if (0 == idx_num_ || NULL == freq_codes_ || NULL == lma_freq_idx_) return false; - if (fwrite(&idx_num_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&idx_num_, sizeof(uint32), 1, fp) != 1) return false; if (fwrite(freq_codes_, sizeof(LmaScoreType), kCodeBookSize, fp) != @@ -183,7 +183,7 @@ bool NGram::load_ngram(FILE *fp) { initialized_ = false; - if (fread(&idx_num_, sizeof(size_t), 1, fp) != 1 ) + if (fread(&idx_num_, sizeof(uint32), 1, fp) != 1 ) return false; if (NULL != lma_freq_idx_) diff --git a/jni/share/spellingtrie.cpp b/jni/share/spellingtrie.cpp index 85be46b..57fa1f0 100644 --- a/jni/share/spellingtrie.cpp +++ b/jni/share/spellingtrie.cpp @@ -640,10 +640,10 @@ bool SpellingTrie::save_spl_trie(FILE *fp) { if (NULL == fp || NULL == spelling_buf_) return false; - if (fwrite(&spelling_size_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&spelling_size_, sizeof(uint32), 1, fp) != 1) return false; - if (fwrite(&spelling_num_, sizeof(size_t), 1, fp) != 1) + if (fwrite(&spelling_num_, sizeof(uint32), 1, fp) != 1) return false; if (fwrite(&score_amplifier_, sizeof(float), 1, fp) != 1) @@ -663,10 +663,10 @@ bool SpellingTrie::load_spl_trie(FILE *fp) { if (NULL == fp) return false; - if (fread(&spelling_size_, sizeof(size_t), 1, fp) != 1) + if (fread(&spelling_size_, sizeof(uint32), 1, fp) != 1) return false; - if (fread(&spelling_num_, sizeof(size_t), 1, fp) != 1) + if (fread(&spelling_num_, sizeof(uint32), 1, fp) != 1) return false; if (fread(&score_amplifier_, sizeof(float), 1, fp) != 1) |