diff options
author | Peng Wu <alexepico@gmail.com> | 2015-04-09 16:13:33 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-04-09 16:13:33 +0800 |
commit | b77d7fb0df28c02389f873717a7557bb7fba62a1 (patch) | |
tree | 451cae296ca9d900f7c5c70130708ad98646e4a4 | |
parent | 941d6c364906a932b4f2874177962e50188e38de (diff) | |
download | libpinyin-b77d7fb0df28c02389f873717a7557bb7fba62a1.tar.gz libpinyin-b77d7fb0df28c02389f873717a7557bb7fba62a1.tar.xz libpinyin-b77d7fb0df28c02389f873717a7557bb7fba62a1.zip |
continue to re-factor Bigram
-rw-r--r-- | src/storage/ngram.h | 20 | ||||
-rw-r--r-- | src/storage/ngram_bdb.cpp | 23 |
2 files changed, 28 insertions, 15 deletions
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 <errno.h> +#include <glib.h> +#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(); |