X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=binlookup.cpp;h=083941de3fdb663aea033ea823ff1aabf310e294;hb=2a322a4ad576d87535ce8a479f7a516da9457e80;hp=363e8dc5e8dbe2c8b4e46bce3ebf8dec8085367d;hpb=4fe8de31aebd9dfe4d4c1616d52599f60cb32204;p=remoteglot-book diff --git a/binlookup.cpp b/binlookup.cpp index 363e8dc..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,19 +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 %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); + 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); + } } }