diff options
Diffstat (limited to 'src/storage/ngram_kyotodb.cpp')
-rw-r--r-- | src/storage/ngram_kyotodb.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/storage/ngram_kyotodb.cpp b/src/storage/ngram_kyotodb.cpp index 98f2f59..560e196 100644 --- a/src/storage/ngram_kyotodb.cpp +++ b/src/storage/ngram_kyotodb.cpp @@ -22,7 +22,7 @@ #include <assert.h> #include <errno.h> #include <kchashdb.h> -#include <kcprotodb.h> +#include <kcstashdb.h> #include "kyotodb_utils.h" @@ -50,16 +50,20 @@ void Bigram::reset(){ } -/* Use ProtoHashDB for load_db/save_db methods. */ +/* Use StashDB for load_db/save_db methods. */ bool Bigram::load_db(const char * dbfile){ reset(); /* create in-memory db. */ - m_db = new ProtoHashDB; + m_db = new StashDB; if ( !m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE) ) return false; + if (!m_db->load_snapshot(dbfile, NULL)) + return false; + +#if 0 /* load db into memory. */ BasicDB * tmp_db = new HashDB; if (!tmp_db->open(dbfile, BasicDB::OREADER)) @@ -70,6 +74,7 @@ bool Bigram::load_db(const char * dbfile){ tmp_db->close(); delete tmp_db; +#endif return true; } @@ -80,6 +85,10 @@ bool Bigram::save_db(const char * dbfile){ if ( ret != 0 && errno != ENOENT) return false; + if (!m_db->dump_snapshot(dbfile, NULL)) + return false; + +#if 0 BasicDB * tmp_db = new HashDB; if ( !tmp_db->open(dbfile, BasicDB::OWRITER|BasicDB::OCREATE) ) @@ -91,6 +100,7 @@ bool Bigram::save_db(const char * dbfile){ tmp_db->synchronize(); tmp_db->close(); delete tmp_db; +#endif return true; } @@ -123,7 +133,7 @@ bool Bigram::load(phrase_token_t index, SingleGram * & single_gram, m_chunk.set_size(vsiz); char * vbuf = (char *) m_chunk.begin(); - assert (vsiz == m_db->get(kbuf, sizeof(phrase_token_t), + check_result (vsiz == m_db->get(kbuf, sizeof(phrase_token_t), vbuf, vsiz)); single_gram = new SingleGram(m_chunk.begin(), vsiz, copy); @@ -196,12 +206,12 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ phrase_token_t index = g_array_index(items, phrase_token_t, i); if ((index & mask) == value) { - assert(remove(index)); + check_result(remove(index)); continue; } SingleGram * gram = NULL; - assert(load(index, gram)); + check_result(load(index, gram)); int num = gram->mask_out(mask, value); if (0 == num) { @@ -210,9 +220,9 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ } if (0 == gram->get_length()) { - assert(remove(index)); + check_result(remove(index)); } else { - assert(store(index, gram)); + check_result(store(index, gram)); } delete gram; |