[Groonga-commit] groonga/grnxx at 7ef1b8f [master] Fix a bug of MinusMerger. (#66)

Back to archive index

susumu.yata null+****@clear*****
Wed Sep 24 13:37:19 JST 2014


susumu.yata	2014-09-24 13:37:19 +0900 (Wed, 24 Sep 2014)

  New Revision: 7ef1b8f0702f3e17d2414061c417f174fc3af9ba
  https://github.com/groonga/grnxx/commit/7ef1b8f0702f3e17d2414061c417f174fc3af9ba

  Message:
    Fix a bug of MinusMerger. (#66)

  Modified files:
    lib/grnxx/merger.cpp

  Modified: lib/grnxx/merger.cpp (+61 -33)
===================================================================
--- lib/grnxx/merger.cpp    2014-09-24 13:28:33 +0900 (fdb7276)
+++ lib/grnxx/merger.cpp    2014-09-24 13:37:19 +0900 (632043a)
@@ -626,46 +626,74 @@ bool MinusMerger::finish(Error *error) {
   // Filter the stream (the larger input) with the hash table.
   const MergerOperatorType operator_type = operator_type_;
   const bool stream_is_1 = stream_records == input_records_1_;
-  for (Int i = 0; i < stream_records->size(); ++i) {
-    auto it = filter.find(stream_records->get_row_id(i));
-    if (it != filter.end()) {
-      filter.erase(it);
-    }
-  }
-
-  for (auto it : filter) {
-    Record record;
-    record.row_id = it.first;
-    switch (operator_type) {
-      case PLUS_MERGER_OPERATOR: {
-        record.score = it.second;
-        break;
+  if (stream_is_1) {
+    for (Int i = 0; i < stream_records->size(); ++i) {
+      auto it = filter.find(stream_records->get_row_id(i));
+      if (it != filter.end()) {
+        continue;
       }
-      case MINUS_MERGER_OPERATOR: {
-        record.score = stream_is_1 ? -it.second : it.second;
-        break;
+      Record record = stream_records->get(i);
+      switch (operator_type) {
+        case PLUS_MERGER_OPERATOR:
+        case MINUS_MERGER_OPERATOR: {
+          break;
+        }
+        case MULTIPLICATION_MERGER_OPERATOR: {
+          // TODO: I'm not sure if it.second should be used?
+          record.score = 0.0;
+          break;
+        }
+        case LHS_MERGER_OPERATOR: {
+          break;
+        }
+        case RHS_MERGER_OPERATOR:
+        case ZERO_MERGER_OPERATOR: {
+          record.score = 0.0;
+          break;
+        }
       }
-      case MULTIPLICATION_MERGER_OPERATOR: {
-        // TODO: I'm not sure if it.second should be used?
-        record.score = 0.0;
-        break;
+      if (!output_records_->push_back(error, record)) {
+        return false;
       }
-      case LHS_MERGER_OPERATOR: {
-        record.score = stream_is_1 ? 0.0 : it.second;
-        break;
+    }
+  } else {
+    for (Int i = 0; i < stream_records->size(); ++i) {
+      auto it = filter.find(stream_records->get_row_id(i));
+      if (it != filter.end()) {
+        filter.erase(it);
       }
-      case RHS_MERGER_OPERATOR: {
-        record.score = stream_is_1 ? it.second : 0.0;
-        break;
+    }
+    for (auto it : filter) {
+      Record record;
+      record.row_id = it.first;
+      switch (operator_type) {
+        case PLUS_MERGER_OPERATOR: {
+          record.score = it.second;
+          break;
+        }
+        case MINUS_MERGER_OPERATOR: {
+          record.score = it.second;
+          break;
+        }
+        case MULTIPLICATION_MERGER_OPERATOR: {
+          // TODO: I'm not sure if it.second should be used?
+          record.score = 0.0;
+          break;
+        }
+        case LHS_MERGER_OPERATOR: {
+          record.score = it.second;
+          break;
+        }
+        case RHS_MERGER_OPERATOR:
+        case ZERO_MERGER_OPERATOR: {
+          record.score = 0.0;
+          break;
+        }
       }
-      case ZERO_MERGER_OPERATOR: {
-        record.score = 0.0;
-        break;
+      if (!output_records_->push_back(error, record)) {
+        return false;
       }
     }
-    if (!output_records_->push_back(error, record)) {
-      return false;
-    }
   }
 
   // Remove out-of-range records.
-------------- next part --------------
HTML����������������������������...
Download 



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