]> git.sesse.net Git - remoteglot-book/blobdiff - binmerger.cpp
Set parallel merges to a value different from parallel loads.
[remoteglot-book] / binmerger.cpp
index 6c162404e416e1c347ee449d83ee82153297ebfb..94e47809d3f2f90837db6df9647ea7028e3d031e 100644 (file)
@@ -2,6 +2,7 @@
 #include <mtbl.h>
 #include <memory>
 #include <string>
+#include <unordered_set>
 #include <string.h>
 #include <assert.h>
 #include "count.pb.h"
@@ -31,11 +32,27 @@ void merge_count(void* userdata,
                if (c0.has_first_timestamp()) {
                        c.set_first_timestamp(c0.first_timestamp());
                }
+               c.set_pgn_file_num(c0.pgn_file_num());
+               c.set_pgn_start_position(c0.pgn_start_position());
        } else {
                c.set_opening_num(c1.opening_num());
                if (c1.has_first_timestamp()) {
                        c.set_first_timestamp(c1.first_timestamp());
                }
+               c.set_pgn_file_num(c1.pgn_file_num());
+               c.set_pgn_start_position(c1.pgn_start_position());
+       }
+
+       // Merge the moves, with deduplication.
+       unordered_set<string> moves;
+       for (int i = 0; i < c0.move_size(); ++i) {
+               moves.insert(c0.move(i));
+               c.add_move(c0.move(i));
+       }
+       for (int i = 0; i < c1.move_size(); ++i) {
+               if (!moves.count(c1.move(i))) {
+                       c.add_move(c1.move(i));
+               }
        }
 
        static string buf;  // Keep allocated.