X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=binloader.cpp;h=730f59279eba946af8073826b08cf775564cf994;hb=f3225963af3ef8bf33b49d5b51a37d36f47e1482;hp=3877ffcaf827aa87267ff4237cc45796e1490641;hpb=b97c4d33965659b1ec9b20dec4ce359b78533d04;p=remoteglot-book diff --git a/binloader.cpp b/binloader.cpp index 3877ffc..730f592 100644 --- a/binloader.cpp +++ b/binloader.cpp @@ -12,7 +12,6 @@ #include #include #include "count.pb.h" -#include "arena.h" #include "hash.h" #define DUMMY_TIMESTAMP 32503680000 @@ -42,7 +41,7 @@ static inline int memcmp_different_len(const void *s1, size_t n1, const void *s2 enum Result { WHITE = 0, DRAW, BLACK }; struct Element { - char *bpfen; // includes prev_board_hash + char bpfen[32]; // includes prev_board_hash int bpfen_len; char move[8]; // Na1xc3+ Result result; @@ -59,7 +58,6 @@ struct Element { struct ShardData { vector elems; - unique_ptr arena; // Used to allocate bpfen. int num_written_subshards = 0; }; @@ -100,7 +98,7 @@ void write_subshard(const char *basename, ShardData* shard, int bucket) c.set_pgn_file_num(e.file_num); c.set_pgn_start_position(e.start_position); } - if (!moves.count(e.move)) { + if (strlen(e.move) > 0 && !moves.count(e.move)) { moves.insert(e.move); c.add_move(e.move); } @@ -119,7 +117,6 @@ void write_subshard(const char *basename, ShardData* shard, int bucket) mtbl_writer_destroy(&mtbl); shard->elems.clear(); - shard->arena.reset(new Arena); } int main(int argc, char **argv) @@ -132,7 +129,6 @@ int main(int argc, char **argv) for (int i = 0; i < num_buckets; ++i) { shards[i].elems.reserve(num_pos_per_subshard); - shards[i].arena.reset(new Arena); } size_t num_elems = 0; @@ -154,6 +150,7 @@ int main(int argc, char **argv) if (bpfen_len == -1) { break; } + assert(bpfen_len <= 32); if (bpfen_len >= int(sizeof(bpfen))) { fprintf(stderr, "Overlong BPFEN (%d bytes)\n", bpfen_len); // exit(1); @@ -217,7 +214,9 @@ int main(int argc, char **argv) // exit(1); break; } - if (fread(&move[0], l, 1, fp) != 1) { + if (l == 0) { + move[0] = 0; + } else if (fread(&move[0], l, 1, fp) != 1) { perror("fread()"); // exit(1); break; @@ -226,7 +225,6 @@ int main(int argc, char **argv) int bucket = hash_key_to_bucket(bpfen, bpfen_len, num_buckets); Element e; - e.bpfen = shards[bucket].arena->alloc(bpfen_len); memcpy(e.bpfen, bpfen, bpfen_len); e.bpfen_len = bpfen_len; strcpy(e.move, move);