[Groonga-commit] groonga/grnxx at 3e3c3b0 [master] Fix a bug of BitwiseCompletionCursor.

Back to archive index

susumu.yata null+****@clear*****
Mon Apr 22 21:29:49 JST 2013


susumu.yata	2013-04-22 21:29:49 +0900 (Mon, 22 Apr 2013)

  New Revision: 3e3c3b0c6aac306204ca85cfb6aa1a7460c9c77c
  https://github.com/groonga/grnxx/commit/3e3c3b0c6aac306204ca85cfb6aa1a7460c9c77c

  Message:
    Fix a bug of BitwiseCompletionCursor.

  Modified files:
    lib/grnxx/alpha/map/cursor.cpp
    test/test_alpha_map.cpp

  Modified: lib/grnxx/alpha/map/cursor.cpp (+1 -1)
===================================================================
--- lib/grnxx/alpha/map/cursor.cpp    2013-04-20 03:42:21 +0900 (246c8d4)
+++ lib/grnxx/alpha/map/cursor.cpp    2013-04-22 21:29:49 +0900 (b42ad55)
@@ -365,7 +365,7 @@ BitwiseCompletionCursor::BitwiseCompletionCursor(
 BitwiseCompletionCursor::~BitwiseCompletionCursor() {}
 
 bool BitwiseCompletionCursor::is_valid(GeoPoint key) const {
-  return ((key.value() ^ query_.value()) & mask_) != 0;
+  return ((key.value() ^ query_.value()) & mask_) == 0;
 }
 
 PrefixCursor::PrefixCursor(Map<Slice> *map, Slice query, size_t min_size,

  Modified: test/test_alpha_map.cpp (+32 -0)
===================================================================
--- test/test_alpha_map.cpp    2013-04-20 03:42:21 +0900 (513911f)
+++ test/test_alpha_map.cpp    2013-04-22 21:29:49 +0900 (f6edf23)
@@ -490,6 +490,36 @@ void test_map_zero(grnxx::alpha::MapType map_type) {
   assert(map->update(1.0, 0.0));
 }
 
+void test_bitwise_completion_cursor(grnxx::alpha::MapType map_type) {
+  grnxx::io::Pool pool;
+  pool.open(grnxx::io::POOL_ANONYMOUS);
+
+  std::unique_ptr<Map<grnxx::alpha::GeoPoint>> map;
+  map.reset(map->create(map_type, pool));
+
+  for (int i = 0; i < 128; ++i) {
+    grnxx::alpha::GeoPoint key;
+    generate_key(&key);
+
+    std::int64_t key_id;
+    map->insert(key, &key_id);
+
+    for (std::size_t j = 0; j <= 64; ++j) {
+      bool found = false;
+      std::unique_ptr<MapCursor<grnxx::alpha::GeoPoint>> cursor(
+          map->open_bitwise_completion_cursor(key, j));
+      assert(cursor->next());
+      do {
+        if (cursor->key_id() == key_id) {
+          assert(cursor->key() == key);
+          found = true;
+        }
+      } while (cursor->next());
+      assert(found);
+    }
+  }
+}
+
 int main() {
   grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
                            grnxx::LOGGER_ENABLE_COUT);
@@ -509,6 +539,7 @@ int main() {
 
   test_map_nan(grnxx::alpha::MAP_ARRAY);
   test_map_zero(grnxx::alpha::MAP_ARRAY);
+  test_bitwise_completion_cursor(grnxx::alpha::MAP_ARRAY);
 
   test_map<std::int8_t>(grnxx::alpha::MAP_DOUBLE_ARRAY);
   test_map<std::int16_t>(grnxx::alpha::MAP_DOUBLE_ARRAY);
@@ -524,6 +555,7 @@ int main() {
 
   test_map_nan(grnxx::alpha::MAP_DOUBLE_ARRAY);
   test_map_zero(grnxx::alpha::MAP_DOUBLE_ARRAY);
+//  test_bitwise_completion_cursor(grnxx::alpha::MAP_DOUBLE_ARRAY);
 
   return 0;
 }
-------------- next part --------------
HTML����������������������������...
Download 



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