]> git.sesse.net Git - pgn-extract/commitdiff
Store a hash of the previous board, to be able to disambigutate transpositions. ...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 00:42:52 +0000 (01:42 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 00:42:52 +0000 (01:42 +0100)
Makefile
farmhash-c.cpp [new file with mode: 0644]
farmhash-c.h [new file with mode: 0644]
output.c

index ab78559f93b5b5f7ba4af6e7dfb9999c016d0a8d..e1fce5631a615e1c941ed5f2a537da35aaaf683c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@
 
 OBJS=grammar.o lex.o map.o decode.o moves.o lists.o apply.o output.o eco.o\
        lines.o end.o main.o hashing.o argsfile.o mymalloc.o fenmatcher.o\
-       taglines.o
+       taglines.o farmhash-c.o
 DEBUGINFO=-g
 
 # These flags are particularly severe on checking warnings.
@@ -40,6 +40,7 @@ CFLAGS+=-c -Wall -Wshadow -Wformat -Wpointer-arith \
        -I/usr/local/lib/ansi-include \
        -O3
 CC=gcc
+LDLIBS=-lfarmhash
 
 # AIX 3.2 Users might like to use these alternatives for CFLAGS and CC.
 # Thanks to Erol Basturk for providing them.
@@ -47,7 +48,7 @@ AIX_CFLAGS=-c -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_ALL_SOURCE
 AIX_CC=xlc
 
 pgn-extract : $(OBJS)
-       $(CC) $(DEBUGINFO) $(OBJS) -o pgn-extract
+       $(CC) $(DEBUGINFO) $(OBJS) $(LDLIBS) -o pgn-extract
 
 purify : $(OBJS)
        purify $(CC) $(DEBUGINFO) $(OBJS) -o pgn-extract
diff --git a/farmhash-c.cpp b/farmhash-c.cpp
new file mode 100644 (file)
index 0000000..ce21a6e
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdint.h>
+#include <farmhash.h>
+
+extern "C" uint64_t farmhash_32(const char* s, size_t len)
+{
+       return util::Hash32(s, len);
+}
diff --git a/farmhash-c.h b/farmhash-c.h
new file mode 100644 (file)
index 0000000..c78283d
--- /dev/null
@@ -0,0 +1,3 @@
+#include <stdint.h>
+
+uint32_t farmhash_32(const char* s, size_t len);
index bb9ee772c58f1fca6323ebca8241e04cfa3a97d6..2792bd807fbb043fed42aa7c9fdd68dc941f5442 100644 (file)
--- a/output.c
+++ b/output.c
@@ -36,6 +36,7 @@
 #include "output.h"
 #include "mymalloc.h"
 #include "eco.h"
+#include "farmhash-c.h"
 
 
             /* Functions for outputting games in the required format. */
@@ -1231,12 +1232,15 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
         timestamp = 32503680000;
     }
 
+    uint16_t prev_board_hash = 0;
+
     for (move = current_game.moves; move != NULL; move = move->next) {
         unsigned int opening = move->eco ? move->eco->cumulative_hash_value : 0;  // Truncate to 32 bits.
 
         // key
-        putc(move->bpfen_len, outputfile);
+        putc(move->bpfen_len + sizeof(prev_board_hash), outputfile);
         fwrite(move->bpfen, move->bpfen_len, 1, outputfile);
+        fwrite(&prev_board_hash, sizeof(prev_board_hash), 1, outputfile);
 
         // value
         putc(result_int, outputfile);
@@ -1248,6 +1252,8 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
         fwrite(&start_position, sizeof(start_position), 1, outputfile);
         putc(strlen((char *)move->move), outputfile);
         fwrite(move->move, strlen((char *)move->move), 1, outputfile);
+
+        prev_board_hash = farmhash_32(move->bpfen, move->bpfen_len);
     }
 }