diff options
author | Peng Wu <alexepico@gmail.com> | 2015-04-21 11:13:50 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-04-21 11:13:50 +0800 |
commit | fb3a0fa827098b9c2f8885e1e55e761deccdac1d (patch) | |
tree | a7952ea0963ccc115854bb59e2270744ec51b8e1 | |
parent | 66e1956cedc8e0e33a900e843cfea842e4483a6a (diff) | |
download | libpinyin-fb3a0fa827098b9c2f8885e1e55e761deccdac1d.tar.gz libpinyin-fb3a0fa827098b9c2f8885e1e55e761deccdac1d.tar.xz libpinyin-fb3a0fa827098b9c2f8885e1e55e761deccdac1d.zip |
add copy parameter to single gram constructor
-rw-r--r-- | src/storage/flexible_single_gram.h | 7 | ||||
-rw-r--r-- | src/storage/ngram.cpp | 7 | ||||
-rw-r--r-- | src/storage/ngram.h | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/storage/flexible_single_gram.h b/src/storage/flexible_single_gram.h index ded2c50..099a826 100644 --- a/src/storage/flexible_single_gram.h +++ b/src/storage/flexible_single_gram.h @@ -42,8 +42,11 @@ class FlexibleSingleGram{ friend class FlexibleBigram; private: MemoryChunk m_chunk; - FlexibleSingleGram(void * buffer, size_t length){ - m_chunk.set_chunk(buffer, length, NULL); + FlexibleSingleGram(void * buffer, size_t length, bool copy){ + if (copy) + m_chunk.set_content(0, buffer, length); + else + m_chunk.set_chunk(buffer, length, NULL); } public: /** diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp index 4f4e787..1c99948 100644 --- a/src/storage/ngram.cpp +++ b/src/storage/ngram.cpp @@ -39,8 +39,11 @@ SingleGram::SingleGram(){ memset(m_chunk.begin(), 0, sizeof(guint32)); } -SingleGram::SingleGram(void * buffer, size_t length){ - m_chunk.set_chunk(buffer, length, NULL); +SingleGram::SingleGram(void * buffer, size_t length, bool copy){ + if (copy) + m_chunk.set_content(0, buffer, length); + else + m_chunk.set_chunk(buffer, length, NULL); } bool SingleGram::get_total_freq(guint32 & total) const{ diff --git a/src/storage/ngram.h b/src/storage/ngram.h index 9b26f5d..62c6544 100644 --- a/src/storage/ngram.h +++ b/src/storage/ngram.h @@ -60,7 +60,7 @@ class SingleGram{ private: MemoryChunk m_chunk; - SingleGram(void * buffer, size_t length); + SingleGram(void * buffer, size_t length, bool copy); public: /** * SingleGram::SingleGram: |