[Groonga-commit] groonga/grnxx at 8a0c6a5 [master] Update max_row_id when the last row is removed.

Back to archive index

susumu.yata null+****@clear*****
Tue Jul 22 15:15:31 JST 2014


susumu.yata	2014-07-22 15:15:31 +0900 (Tue, 22 Jul 2014)

  New Revision: 8a0c6a574a9d47ed4d3fdef9bb336c8793b0fe6f
  https://github.com/groonga/grnxx/commit/8a0c6a574a9d47ed4d3fdef9bb336c8793b0fe6f

  Message:
    Update max_row_id when the last row is removed.

  Modified files:
    lib/grnxx/table.cpp
    test/test_grnxx.cpp

  Modified: lib/grnxx/table.cpp (+12 -0)
===================================================================
--- lib/grnxx/table.cpp    2014-07-22 13:33:51 +0900 (9797a0a)
+++ lib/grnxx/table.cpp    2014-07-22 15:15:31 +0900 (e3a4935)
@@ -431,6 +431,18 @@ bool Table::remove_row(Error *error, Int row_id) {
   }
   unset_bit(row_id);
   --num_rows_;
+  if (num_rows_ == 0) {
+    max_row_id_ = MIN_ROW_ID - 1;
+  } else if (row_id == max_row_id()) {
+    Int block_id = (max_row_id() - 1) / 64;
+    while (block_id >= 0) {
+      if (bitmap_[block_id] != 0) {
+        break;
+      }
+      --block_id;
+    }
+    max_row_id_ = (block_id * 64) + 63 - ::__builtin_clzll(bitmap_[block_id]);
+  }
   return true;
 }
 

  Modified: test/test_grnxx.cpp (+16 -0)
===================================================================
--- test/test_grnxx.cpp    2014-07-22 13:33:51 +0900 (1f59edb)
+++ test/test_grnxx.cpp    2014-07-22 15:15:31 +0900 (0143542)
@@ -244,11 +244,15 @@ void test_bitmap() {
                              grnxx::Datum(), &row_id));
     assert(row_id == (i + 1));
   }
+  assert(table->num_rows() == NUM_ROWS);
+  assert(table->max_row_id() == NUM_ROWS);
 
   for (int i = 0; i < NUM_ROWS; ++i) {
     grnxx::Int row_id = i + 1;
     assert(table->remove_row(&error, row_id));
   }
+  assert(table->num_rows() == 0);
+  assert(table->max_row_id() == (grnxx::MIN_ROW_ID - 1));
 
   for (int i = 0; i < NUM_ROWS; ++i) {
     grnxx::Int row_id;
@@ -256,11 +260,15 @@ void test_bitmap() {
                              grnxx::Datum(), &row_id));
     assert(row_id == (i + 1));
   }
+  assert(table->num_rows() == NUM_ROWS);
+  assert(table->max_row_id() == NUM_ROWS);
 
   for (int i = 0; i < NUM_ROWS; i += 2) {
     grnxx::Int row_id = i + 1;
     assert(table->remove_row(&error, row_id));
   }
+  assert(table->num_rows() == (NUM_ROWS / 2));
+  assert(table->max_row_id() == NUM_ROWS);
 
   for (int i = 0; i < NUM_ROWS; i += 2) {
     grnxx::Int row_id;
@@ -268,6 +276,14 @@ void test_bitmap() {
                              grnxx::Datum(), &row_id));
     assert(row_id == (i + 1));
   }
+  assert(table->num_rows() == NUM_ROWS);
+  assert(table->max_row_id() == NUM_ROWS);
+
+  for (int i = 0; i < NUM_ROWS; ++i) {
+    grnxx::Int row_id = NUM_ROWS - i;
+    assert(table->remove_row(&error, row_id));
+    assert(table->max_row_id() == (row_id - 1));
+  }
 }
 
 void test_column() {
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index