X-Git-Url: https://git.sesse.net/?p=remoteglot-book;a=blobdiff_plain;f=binlookup.cpp;h=3c969e2dc2701e72238b7f303bff1f00694aad2e;hp=5b5fd40f6101cfd29634506294dc03b8ffc7d719;hb=19c49abb677f8cbf5b290e71dbcad382558d8cc5;hpb=62de36318c4a6347a3bd6f2128de649d209e804b diff --git a/binlookup.cpp b/binlookup.cpp index 5b5fd40..3c969e2 100644 --- a/binlookup.cpp +++ b/binlookup.cpp @@ -6,13 +6,14 @@ #include #include #include -#include "count.h" +#include "count.pb.h" using namespace std; int main(int argc, char **argv) { - const char *hex_prefix = argv[2]; + int num_buckets = atoi(argv[2]); + const char *hex_prefix = argv[3]; const int prefix_len = strlen(hex_prefix) / 2; uint8_t *prefix = new uint8_t[prefix_len]; @@ -26,20 +27,26 @@ int main(int argc, char **argv) prefix[i] = k; } - mtbl_reader* mtbl = mtbl_reader_init(argv[1], NULL); - const mtbl_source *src = mtbl_reader_source(mtbl); - mtbl_iter *it = mtbl_source_get_prefix(src, prefix, prefix_len); + for (int i = 0; i < num_buckets; ++i) { + char filename[256]; + snprintf(filename, sizeof(filename), "%s.part%04d", argv[1], i); - const uint8_t *key, *val; - size_t len_key, len_val; + mtbl_reader* mtbl = mtbl_reader_init(filename, NULL); + const mtbl_source *src = mtbl_reader_source(mtbl); + mtbl_iter *it = mtbl_source_get_prefix(src, prefix, prefix_len); - 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 %d\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, - c->num_elo); + const uint8_t *key, *val; + size_t len_key, len_val; + + while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) { + string move((char *)(key + prefix_len), len_key - prefix_len); + Count c; + c.ParseFromArray(val, len_val); + printf("%s %d %d %d %u %f %f %d %ld\n", move.c_str(), + c.white(), c.draw(), c.black(), c.opening_num(), + double(c.sum_white_elo()) / c.num_elo(), + double(c.sum_black_elo()) / c.num_elo(), + c.num_elo(), c.first_timestamp()); + } } }