#include <memory>
#include <string>
#include <string.h>
+#include <farmhash.h>
#include "count.pb.h"
+#include "merge_count.h"
#include "hash.h"
using namespace std;
srcs[bucket] = mtbl_reader_source(mtbls[bucket]);
}
- mtbl_iter *it = mtbl_source_get(srcs[bucket], bpfen, bpfen_len);
+ // Give back the hash of the position to be kind to the user
+ uint16_t board_hash = util::Hash32((const char *)bpfen, bpfen_len);
+ printf("%d\n", board_hash);
+
+ mtbl_iter *it = mtbl_source_get_prefix(srcs[bucket], bpfen, bpfen_len);
const uint8_t *key, *val;
size_t len_key, len_val;
- if (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
- Count c;
- c.ParseFromArray(val, len_val);
- printf("%d %d %d %u %f %f %d %ld %d %ld",
+ Count c;
+ bool has_c = false;
+ while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
+ if (has_c) {
+ Count tmpc;
+ tmpc.ParseFromArray(val, len_val);
+ c = merge_count(c, tmpc);
+ } else {
+ c.ParseFromArray(val, len_val);
+ has_c = true;
+ }
+ }
+
+ if (has_c) {
+ printf("%d %d %d %u %ld %ld %d %ld %d %ld",
c.white(), c.draw(), c.black(), c.opening_num(),
- double(c.sum_white_elo()) / c.num_elo(),
- double(c.sum_black_elo()) / c.num_elo(),
+ c.sum_white_elo(),
+ c.sum_black_elo(),
c.num_elo(), c.first_timestamp(),
c.pgn_file_num(),
c.pgn_start_position());