From b77d7fb0df28c02389f873717a7557bb7fba62a1 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 9 Apr 2015 16:13:33 +0800 Subject: continue to re-factor Bigram --- src/storage/ngram.h | 20 +++++--------------- src/storage/ngram_bdb.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src/storage') diff --git a/src/storage/ngram.h b/src/storage/ngram.h index e4045a9..e0aee0b 100644 --- a/src/storage/ngram.h +++ b/src/storage/ngram.h @@ -117,7 +117,7 @@ public: * */ bool get_freq(/* in */ phrase_token_t token, - /* out */ guint32 & freq) const; + /* out */ guint32 & freq) const; /** * SingleGram::set_freq: @@ -129,7 +129,7 @@ public: * */ bool set_freq(/* in */ phrase_token_t token, - /* in */ guint32 freq); + /* in */ guint32 freq); /** * SingleGram::get_total_freq: @@ -192,13 +192,7 @@ class Bigram{ private: DB * m_db; - void reset(){ - if ( m_db ){ - m_db->sync(m_db, 0); - m_db->close(m_db, 0); - m_db = NULL; - } - } + void reset(); public: /** @@ -207,9 +201,7 @@ public: * The constructor of the Bigram. * */ - Bigram(){ - m_db = NULL; - } + Bigram(); /** * Bigram::~Bigram: @@ -217,9 +209,7 @@ public: * The destructor of the Bigram. * */ - ~Bigram(){ - reset(); - } + ~Bigram(); /** * Bigram::load_db: diff --git a/src/storage/ngram_bdb.cpp b/src/storage/ngram_bdb.cpp index 954e701..e07127b 100644 --- a/src/storage/ngram_bdb.cpp +++ b/src/storage/ngram_bdb.cpp @@ -19,8 +19,31 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include "memory_chunk.h" +#include "novel_types.h" #include "ngram.h" +using namespace pinyin; + + +Bigram::Bigram(){ + m_db = NULL; +} + +Bigram::~Bigram(){ + reset(); +} + +void Bigram::reset(){ + if ( m_db ){ + m_db->sync(m_db, 0); + m_db->close(m_db, 0); + m_db = NULL; + } +} + bool Bigram::load_db(const char * dbfile){ reset(); -- cgit