]> git.sesse.net Git - remoteglot/blob - book/binlookup.cpp
5ed372d851ff2cd1bcaf8c46013710ac9602d113
[remoteglot] / book / binlookup.cpp
1 #include <stdio.h>
2 #include <vector>
3 #include <mtbl.h>
4 #include <algorithm>
5 #include <utility>
6 #include <memory>
7 #include <string>
8 #include <string.h>
9 #include "count.h"
10
11 using namespace std;
12
13 int main(int argc, char **argv)
14 {
15         const char *hex_prefix = argv[2];
16         const int prefix_len = strlen(hex_prefix) / 2;
17         uint8_t *prefix = new uint8_t[prefix_len];
18
19         for (int i = 0; i < prefix_len; ++i) {
20                 char x[3];
21                 x[0] = hex_prefix[i * 2 + 0];
22                 x[1] = hex_prefix[i * 2 + 1];
23                 x[2] = 0;
24                 int k;
25                 sscanf(x, "%02x", &k);
26                 prefix[i] = k;
27         }
28
29         mtbl_reader* mtbl = mtbl_reader_init(argv[1], NULL);
30         const mtbl_source *src = mtbl_reader_source(mtbl);
31         mtbl_iter *it = mtbl_source_get_prefix(src, prefix, prefix_len);
32
33         const uint8_t *key, *val;
34         size_t len_key, len_val;
35
36         while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
37                 string move((char *)(key + prefix_len), len_key - prefix_len);
38                 const Count* c = (Count *)val;
39                 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);
40         }
41 }