[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] hash collisions
From: |
Gunnar Farnebäck |
Subject: |
Re: [gnugo-devel] hash collisions |
Date: |
Thu, 17 Jun 2004 02:19:33 +0200 |
User-agent: |
EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.3 (sparc-sun-solaris2.9) MULE/5.0 (SAKAKI) |
Doug wrote:
> I think the intent is to see leading zeros (in particular,
> hashdata_to_string prints the hash values next to each other, so without
> leading zeros there's some ambiguity)
Correct.
> but %0lx doesn't do this.
Too bad.
> %08x works for me, but I don't know the right platform independent
> construct.
With some luck the patch below should solve the problem properly.
/Gunnar
Index: engine/hash.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.c,v
retrieving revision 1.28
diff -u -r1.28 hash.c
--- engine/hash.c 7 Jun 2004 17:15:52 -0000 1.28
+++ engine/hash.c 17 Jun 2004 00:10:48 -0000
@@ -168,8 +168,8 @@
}
-#define BUFFER_SIZE (1 + NUM_HASHVALUES * (1 + (CHAR_BIT * SIZEOF_HASHVALUE \
- - 1) / 4))
+#define HASHVALUE_NUM_DIGITS (1 + (CHAR_BIT * SIZEOF_HASHVALUE - 1) / 4)
+#define BUFFER_SIZE (1 + NUM_HASHVALUES * HASHVALUE_NUM_DIGITS)
char *
hashdata_to_string(Hash_data *hashdata)
{
@@ -178,7 +178,8 @@
int k;
for (k = 0; k < NUM_HASHVALUES; k++) {
- n += sprintf(buffer + n, HASHVALUE_PRINT_FORMAT, hashdata->hashval[k]);
+ n += sprintf(buffer + n, HASHVALUE_PRINT_FORMAT,
+ HASHVALUE_NUM_DIGITS, hashdata->hashval[k]);
gg_assert(n < BUFFER_SIZE);
}
Index: engine/hash.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.h,v
retrieving revision 1.29
diff -u -r1.29 hash.h
--- engine/hash.h 27 May 2004 00:08:47 -0000 1.29
+++ engine/hash.h 17 Jun 2004 00:10:48 -0000
@@ -52,7 +52,7 @@
*/
typedef unsigned long Hashvalue;
#define SIZEOF_HASHVALUE SIZEOF_LONG
-#define HASHVALUE_PRINT_FORMAT "%0lx"
+#define HASHVALUE_PRINT_FORMAT "%0*lx"
/* for testing: Enables a lot of checks. */
#define CHECK_HASHING 0