From c74ba4bbf10f2913c2c775f6f54266ce9df151f1 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 4 Feb 2016 11:29:17 +0800 Subject: write remove_index method --- src/storage/phrase_large_table3_bdb.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/storage/phrase_large_table3_bdb.cpp') diff --git a/src/storage/phrase_large_table3_bdb.cpp b/src/storage/phrase_large_table3_bdb.cpp index fe27494..328aec6 100644 --- a/src/storage/phrase_large_table3_bdb.cpp +++ b/src/storage/phrase_large_table3_bdb.cpp @@ -278,4 +278,40 @@ int PhraseLargeTable3::add_index(int phrase_length, return result; } +int PhraseLargeTable3::remove_index(int phrase_length, + /* in */ const ucs4_t phrase[], + /* in */ phrase_token_t token) { + assert(NULL != m_db); + assert(NULL != m_entry); + + DBT db_key; + memset(&db_key, 0, sizeof(DBT)); + db_key.data = (void *) phrase; + db_key.size = phrase_length * sizeof(ucs4_t); + + DBT db_data; + memset(&db_data, 0, sizeof(DBT)); + int ret = m_db->get(m_db, NULL, &db_key, &db_data, 0); + if (ret != 0) + return ERROR_REMOVE_ITEM_DONOT_EXISTS; + + m_entry->m_chunk.set_chunk(db_data.data, db_data.size, NULL); + + int result = m_entry->remove_index(token); + if (ERROR_OK != result) + return result; + + /* removed the token. */ + memset(&db_data, 0, sizeof(DBT)); + db_data.data = m_entry->m_chunk.begin(); + db_data.size = m_entry->m_chunk.size(); + + ret = m_db->put(m_db, NULL, &db_key, &db_data, 0); + if (ret != 0) + return ERROR_FILE_CORRUPTION; + + return ERROR_OK; +} + + }; -- cgit