Store sum and number of Elo values instead of averages, for easier merging.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 9 Dec 2014 19:22:33 +0000 (20:22 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 9 Dec 2014 19:22:33 +0000 (20:22 +0100)
book/binloader.cpp
book/binlookup.cpp
book/count.h

index e4b40a6..88fb5ff 100644 (file)
@@ -82,8 +82,6 @@ int main(int argc, char **argv)
        printf("Writing SSTable...\n");
        mtbl_writer* mtbl = mtbl_writer_init("open.mtbl", NULL);
        Count c;
-       int num_elo = 0;
-       double sum_white_elo = 0.0, sum_black_elo = 0.0;
        for (int i = 0; i < elems.size(); ++i) {
                if (elems[i].result == WHITE) {
                        ++c.white;
@@ -94,19 +92,15 @@ int main(int argc, char **argv)
                }
                c.opening_num = elems[i].opening_num;
                if (elems[i].white_elo >= 100 && elems[i].black_elo >= 100) {
-                       sum_white_elo += elems[i].white_elo;
-                       sum_black_elo += elems[i].black_elo;
-                       ++num_elo;
+                       c.sum_white_elo += elems[i].white_elo;
+                       c.sum_black_elo += elems[i].black_elo;
+                       ++c.num_elo;
                }
                if (i == elems.size() - 1 || elems[i].bpfen_and_move != elems[i + 1].bpfen_and_move) {
-                       c.avg_white_elo = sum_white_elo / num_elo;
-                       c.avg_black_elo = sum_black_elo / num_elo;
                        mtbl_writer_add(mtbl,
                                (const uint8_t *)elems[i].bpfen_and_move.data(), elems[i].bpfen_and_move.size(),
                                (const uint8_t *)&c, sizeof(c));
                        c = Count();
-                       num_elo = 0;
-                       sum_white_elo = sum_black_elo = 0.0;
                }
        }
        mtbl_writer_destroy(&mtbl);
index 5ed372d..363e8dc 100644 (file)
@@ -36,6 +36,9 @@ int main(int argc, char **argv)
        while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
                string move((char *)(key + prefix_len), len_key - prefix_len);
                const Count* c = (Count *)val;
-               printf("%s %d %d %d %d %f %f\n", move.c_str(), c->white, c->draw, c->black, c->opening_num, c->avg_white_elo, c->avg_black_elo);
+               printf("%s %d %d %d %d %f %f\n", move.c_str(),
+                       c->white, c->draw, c->black, c->opening_num,
+                       float(c->sum_white_elo) / c->num_elo,
+                       float(c->sum_black_elo) / c->num_elo);
        }
 }
index 1d8043f..3024b89 100644 (file)
@@ -4,6 +4,7 @@ struct Count {
        int draw = 0;
        int black = 0;
        int opening_num = -1;
-       float avg_white_elo = 0.0;
-       float avg_black_elo = 0.0;
+       unsigned long long sum_white_elo = 0;
+       unsigned long long sum_black_elo = 0;
+       int num_elo = 0;
 };