summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-03 16:58:49 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-03 16:58:49 +0800
commit17eca1b8defe9f890790b1c897407c471ac0562f (patch)
tree1d7d21e6b9278bbbaf8a024cdf4aa5e1527bbd08
parent2c39a250adcef967493bcfc1201435f91249ad70 (diff)
downloadlibpinyin-17eca1b8defe9f890790b1c897407c471ac0562f.tar.gz
libpinyin-17eca1b8defe9f890790b1c897407c471ac0562f.tar.xz
libpinyin-17eca1b8defe9f890790b1c897407c471ac0562f.zip
use copy_bdb function in ngram_bdb.cpp
-rw-r--r--src/storage/ngram_bdb.cpp45
1 files changed, 2 insertions, 43 deletions
diff --git a/src/storage/ngram_bdb.cpp b/src/storage/ngram_bdb.cpp
index 1e2cbe1..65cd699 100644
--- a/src/storage/ngram_bdb.cpp
+++ b/src/storage/ngram_bdb.cpp
@@ -70,30 +70,9 @@ bool Bigram::load_db(const char * dbfile){
if ( ret != 0 )
return false;
- DBC * cursorp = NULL;
- DBT key, data;
-
- /* Get a cursor */
- tmp_db->cursor(tmp_db, NULL, &cursorp, 0);
-
- if (NULL == cursorp)
+ if ( !copy_bdb(tmp_db, m_db) )
return false;
- /* Initialize our DBTs. */
- memset(&key, 0, sizeof(DBT));
- memset(&data, 0, sizeof(DBT));
-
- /* Iterate over the database, retrieving each record in turn. */
- while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0) {
- int ret = m_db->put(m_db, NULL, &key, &data, 0);
- assert(ret == 0);
- }
- assert (ret == DB_NOTFOUND);
-
- /* Cursors must be closed */
- if ( cursorp != NULL )
- cursorp->c_close(cursorp);
-
if ( tmp_db != NULL )
tmp_db->close(tmp_db, 0);
@@ -118,29 +97,9 @@ bool Bigram::save_db(const char * dbfile){
if ( ret != 0 )
return false;
- DBC * cursorp = NULL;
- DBT key, data;
- /* Get a cursor */
- m_db->cursor(m_db, NULL, &cursorp, 0);
-
- if (NULL == cursorp)
+ if ( !copy_bdb(m_db, tmp_db) )
return false;
- /* Initialize our DBTs. */
- memset(&key, 0, sizeof(DBT));
- memset(&data, 0, sizeof(DBT));
-
- /* Iterate over the database, retrieving each record in turn. */
- while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0) {
- int ret = tmp_db->put(tmp_db, NULL, &key, &data, 0);
- assert(ret == 0);
- }
- assert (ret == DB_NOTFOUND);
-
- /* Cursors must be closed */
- if ( cursorp != NULL )
- cursorp->c_close(cursorp);
-
if ( tmp_db != NULL ) {
tmp_db->sync(m_db, 0);
tmp_db->close(tmp_db, 0);