From fb3a0fa827098b9c2f8885e1e55e761deccdac1d Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 21 Apr 2015 11:13:50 +0800 Subject: add copy parameter to single gram constructor --- src/storage/flexible_single_gram.h | 7 +++++-- src/storage/ngram.cpp | 7 +++++-- src/storage/ngram.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') 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: -- cgit