14 int main(int argc, char **argv)
16 int num_buckets = atoi(argv[2]);
17 mtbl_reader** mtbls = new mtbl_reader*[num_buckets];
18 const mtbl_source** srcs = new const mtbl_source*[num_buckets];
19 for (int i = 0; i < num_buckets; ++i) {
24 while (!feof(stdin)) {
26 if (fgets(hex_bpfen, sizeof(hex_bpfen), stdin) == NULL) {
29 char *ptr = strchr(hex_bpfen, '\n');
34 const int bpfen_len = strlen(hex_bpfen) / 2;
35 uint8_t *bpfen = new uint8_t[bpfen_len];
37 for (int i = 0; i < bpfen_len; ++i) {
39 x[0] = hex_bpfen[i * 2 + 0];
40 x[1] = hex_bpfen[i * 2 + 1];
43 sscanf(x, "%02x", &k);
47 int bucket = hash_key_to_bucket((const char *)bpfen, bpfen_len, num_buckets);
48 if (mtbls[bucket] == NULL) {
50 snprintf(filename, sizeof(filename), "%s.part%04d", argv[1], bucket);
52 mtbls[bucket] = mtbl_reader_init(filename, NULL);
53 srcs[bucket] = mtbl_reader_source(mtbls[bucket]);
56 mtbl_iter *it = mtbl_source_get(srcs[bucket], bpfen, bpfen_len);
58 const uint8_t *key, *val;
59 size_t len_key, len_val;
61 while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
63 c.ParseFromArray(val, len_val);
64 printf("%d %d %d %u %f %f %d %ld %ld",
65 c.white(), c.draw(), c.black(), c.opening_num(),
66 double(c.sum_white_elo()) / c.num_elo(),
67 double(c.sum_black_elo()) / c.num_elo(),
68 c.num_elo(), c.first_timestamp(),
69 c.pgn_start_position());
70 for (int j = 0; j < c.move_size(); ++j) {
71 printf(" %s", c.move(j).c_str());
76 mtbl_iter_destroy(&it);
79 for (int i = 0; i < num_buckets; ++i) {
80 if (mtbls[i] != NULL) {
81 mtbl_reader_destroy(&mtbls[i]);