X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=book%2Fbinlookup.cpp;fp=book%2Fbinlookup.cpp;h=5ed372d851ff2cd1bcaf8c46013710ac9602d113;hp=0000000000000000000000000000000000000000;hb=7dfa8135cabec7261a2a255e7b5edd679e75da0b;hpb=7ac37d77ecacc4f33d8bc76d80e3fb6c7632fb92 diff --git a/book/binlookup.cpp b/book/binlookup.cpp new file mode 100644 index 0000000..5ed372d --- /dev/null +++ b/book/binlookup.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "count.h" + +using namespace std; + +int main(int argc, char **argv) +{ + const char *hex_prefix = argv[2]; + const int prefix_len = strlen(hex_prefix) / 2; + uint8_t *prefix = new uint8_t[prefix_len]; + + for (int i = 0; i < prefix_len; ++i) { + char x[3]; + x[0] = hex_prefix[i * 2 + 0]; + x[1] = hex_prefix[i * 2 + 1]; + x[2] = 0; + int k; + sscanf(x, "%02x", &k); + 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); + + 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 %d %f %f\n", move.c_str(), c->white, c->draw, c->black, c->opening_num, c->avg_white_elo, c->avg_black_elo); + } +}