X-Git-Url: https://git.sesse.net/?p=remoteglot-book;a=blobdiff_plain;f=binlookup.cpp;h=083941de3fdb663aea033ea823ff1aabf310e294;hp=488a8e3912fcbfa7ccc2c6843cb121bcec49ee52;hb=2a322a4ad576d87535ce8a479f7a516da9457e80;hpb=d0b08188b8f9e70f2f5651b179b44e7cf992c85b diff --git a/binlookup.cpp b/binlookup.cpp index 488a8e3..083941d 100644 --- a/binlookup.cpp +++ b/binlookup.cpp @@ -12,7 +12,8 @@ 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,25 @@ 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 %u %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); + const Count* c = (Count *)val; + printf("%s %d %d %d %u %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); + } } }