diff options
author | Peng Wu <alexepico@gmail.com> | 2012-05-21 14:56:50 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-05-21 14:56:50 +0800 |
commit | 34de36eabbc3baac56885e01fa2ec79ba7fb5cc6 (patch) | |
tree | a02d1f43a569cfbbf9b201a41451a1436266c234 /utils/utils_helper.h | |
parent | 931df7d5a0924cde0c5b249b5f82a8d5bf9039b5 (diff) | |
download | libpinyin-34de36eabbc3baac56885e01fa2ec79ba7fb5cc6.tar.gz libpinyin-34de36eabbc3baac56885e01fa2ec79ba7fb5cc6.tar.xz libpinyin-34de36eabbc3baac56885e01fa2ec79ba7fb5cc6.zip |
write save_phrase_index
Diffstat (limited to 'utils/utils_helper.h')
-rw-r--r-- | utils/utils_helper.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/utils/utils_helper.h b/utils/utils_helper.h index 59286db..2f143c9 100644 --- a/utils/utils_helper.h +++ b/utils/utils_helper.h @@ -33,7 +33,7 @@ static bool load_phrase_index(FacadePhraseIndex * phrase_index) { chunk = new MemoryChunk; bool retval = chunk->load(bin_file); if (!retval) { - fprintf(stderr, "open %s failed!\n", bin_file); + fprintf(stderr, "load %s failed!\n", bin_file); return false; } @@ -42,5 +42,24 @@ static bool load_phrase_index(FacadePhraseIndex * phrase_index) { return true; } +static bool save_phrase_index(FacadePhraseIndex * phrase_index) { + MemoryChunk * new_chunk = NULL; + for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { + const char * bin_file = pinyin_phrase_files[i]; + if (NULL == bin_file) + continue; + + new_chunk = new MemoryChunk; + phrase_index->store(i, new_chunk); + bool retval = new_chunk->save(bin_file); + if (!retval) { + fprintf(stderr, "save %s failed.", bin_file); + return false; + } + + phrase_index->load(i, new_chunk); + } + return true; +} #endif |