summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/memory_chunk.h2
-rw-r--r--src/storage/phrase_index.h4
-rw-r--r--src/storage/phrase_index_logger.h4
-rw-r--r--tests/storage/test_phrase_index_logger.cpp4
4 files changed, 7 insertions, 7 deletions
diff --git a/src/include/memory_chunk.h b/src/include/memory_chunk.h
index 6fd9d9a..3d9ea35 100644
--- a/src/include/memory_chunk.h
+++ b/src/include/memory_chunk.h
@@ -119,7 +119,7 @@ public:
return m_data_end;
}
- size_t size(){
+ size_t size() const{
return m_data_end - m_data_begin;
}
diff --git a/src/storage/phrase_index.h b/src/storage/phrase_index.h
index 17d81c4..e1d4de6 100644
--- a/src/storage/phrase_index.h
+++ b/src/storage/phrase_index.h
@@ -137,14 +137,14 @@ public:
void append_pronunciation(PinyinKey * pinyin, guint32 freq);
void remove_nth_pronunciation(size_t index);
- bool operator == (PhraseItem & rhs){
+ bool operator == (const PhraseItem & rhs) const{
if (m_chunk.size() != rhs.m_chunk.size())
return false;
return memcmp(m_chunk.begin(), rhs.m_chunk.begin(),
m_chunk.size()) == 0;
}
- bool operator != (PhraseItem & rhs){
+ bool operator != (const PhraseItem & rhs) const{
return ! (*this == rhs);
}
};
diff --git a/src/storage/phrase_index_logger.h b/src/storage/phrase_index_logger.h
index 95f8e8b..c74169d 100644
--- a/src/storage/phrase_index_logger.h
+++ b/src/storage/phrase_index_logger.h
@@ -98,9 +98,10 @@ public:
m_chunk->get_content(offset, &token, sizeof(phrase_token_t));
offset += sizeof(phrase_token_t);
+ oldone->set_size(0); newone->set_size(0);
+
switch(log_type){
case LOG_ADD_RECORD:{
- oldone->set_size(0);
size_t len = 0;
m_chunk->get_content(offset, &len, sizeof(size_t));
offset += sizeof(size_t);
@@ -109,7 +110,6 @@ public:
break;
}
case LOG_REMOVE_RECORD:{
- newone->set_size(0);
size_t len = 0;
m_chunk->get_content(offset, &len, sizeof(size_t));
offset += sizeof(size_t);
diff --git a/tests/storage/test_phrase_index_logger.cpp b/tests/storage/test_phrase_index_logger.cpp
index 965d2c6..ec5cc79 100644
--- a/tests/storage/test_phrase_index_logger.cpp
+++ b/tests/storage/test_phrase_index_logger.cpp
@@ -46,7 +46,7 @@ int main(int argc, char * argv[]){
chunk = new MemoryChunk;
chunk->load("../../data/gb_char.bin");
new_chunk = new MemoryChunk;
- phrase_index.diff(1, chunk, new_chunk);
+ assert(phrase_index.diff(1, chunk, new_chunk));
new_chunk->save("/tmp/gb_char.dbin");
delete new_chunk;
@@ -55,7 +55,7 @@ int main(int argc, char * argv[]){
phrase_index.load(1, chunk);
new_chunk = new MemoryChunk;
new_chunk->load("/tmp/gb_char.dbin");
- phrase_index.merge(1, new_chunk);
+ assert(phrase_index.merge(1, new_chunk));
chunk = new MemoryChunk;
phrase_index.store(1, chunk);
chunk->save("/tmp/gb_char2.bin");