[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tidy up hashsize calculation
From: |
Anil Mungal |
Subject: |
Tidy up hashsize calculation |
Date: |
Wed, 12 Mar 2003 11:31:06 -0500 |
Simon, I've added a new function CalcHashSize(int).
The int parameter specifies the size of the hash table.
The minimum table size is defined by HASHSLOTS.
This reduces duplication of code when doing hashsize commands,
as stated in one of your comments in main.c.
Is there a need to be able to size/resize the pawn tables?
The diff from today's CVS files.
diff -r -up ../gnuchess-5.06/src/cmd.c src/cmd.c
--- ../gnuchess-5.06/src/cmd.c 2003-03-12 11:17:11.000000000 -0500
+++ src/cmd.c 2003-03-12 10:53:57.000000000 -0500
@@ -278,13 +278,7 @@ void cmd_hashsize(void)
} else {
int i;
i = atoi (token[1]);
- TTHashMask = 0;
- while ((i >>= 1) > 0) {
- TTHashMask <<= 1;
- TTHashMask |= 1;
- }
- HashSize = TTHashMask + 1;
- printf ("Adjusting HashSize to %d slots\n", HashSize);
+ CalcHashSize(i);
InitHashTable ();
}
}
diff -r -up ../gnuchess-5.06/src/common.h src/common.h
--- ../gnuchess-5.06/src/common.h 2003-03-07 10:15:25.000000000 -0500
+++ src/common.h 2003-03-12 11:00:02.000000000 -0500
@@ -539,6 +539,7 @@ void InitDistance (void);
void InitVars (void);
void InitHashCode (void);
void InitHashTable (void);
+void CalcHashSize (int);
void NewPosition (void);
void InitFICS (void);
void InitInput (void);
diff -r -up ../gnuchess-5.06/src/hash.c src/hash.c
--- ../gnuchess-5.06/src/hash.c 2002-12-17 07:52:40.000000000 -0500
+++ src/hash.c 2003-03-12 10:36:32.000000000 -0500
@@ -90,3 +90,32 @@ void ShowHashKey (HashType HashKey)
a2 = (HashKey >> 32);
printf ("Hashkey = %lx%lx\n", a2, a1);
}
+
+void CalcHashSize (int tablesize)
+/***************************************************************************
+ *
+ * Calculates the ttable hashtable size, ttable hashmask, and pawntable
hashmask
+ *
+ ***************************************************************************/
+{
+ int i;
+
+ i = (tablesize < HASHSLOTS ? HASHSLOTS : tablesize);
+
+ TTHashMask = 0;
+ while ((i>>=1) > 0)
+ {
+ TTHashMask <<= 1;
+ TTHashMask |= 1;
+ }
+ HashSize = TTHashMask + 1;
+ printf ("Adjusting HashSize to %d slots\n", HashSize);
+
+ i = PAWNSLOTS;
+ PHashMask = 0;
+ while ((i>>=1) > 0)
+ {
+ PHashMask <<= 1;
+ PHashMask |= 1;
+ }
+}
diff -r -up ../gnuchess-5.06/src/init.c src/init.c
--- ../gnuchess-5.06/src/init.c 2003-03-12 11:16:49.000000000 -0500
+++ src/init.c 2003-03-12 10:55:31.000000000 -0500
@@ -672,23 +672,8 @@ void InitVars (void)
phase = PHASE;
/* Calculate the ttable hashmask & pawntable hashmask */
- if ( HashSize == 0 ){
- i = HASHSLOTS;
- TTHashMask = 0;
- while ((i>>=1) > 0)
- {
- TTHashMask <<= 1;
- TTHashMask |= 1;
- }
- HashSize = TTHashMask + 1;
- }
- i = PAWNSLOTS;
- PHashMask = 0;
- while ((i>>=1) > 0)
- {
- PHashMask <<= 1;
- PHashMask |= 1;
- }
+ if ( HashSize == 0 )
+ CalcHashSize(HashSize);
signal (SIGINT, EndSearch);
diff -r -up ../gnuchess-5.06/src/main.c src/main.c
--- ../gnuchess-5.06/src/main.c 2003-03-12 11:17:04.000000000 -0500
+++ src/main.c 2003-03-12 10:58:11.000000000 -0500
@@ -409,23 +409,9 @@ int main (int argc, char *argv[])
HashSize = 0 ; /* Set HashSize zero */
+ if (opt_hash != 0)
+ CalcHashSize(opt_hash);
- if ( opt_hash != 0){
- /*
- * This code should be refactored from here, cmd.c, and init.c
- * into the hashtable allocation. SRW Implementing command lines
- * changes.
- */
- int i;
- i = opt_hash;
- TTHashMask = 0;
- while ((i >>= 1) > 0) {
- TTHashMask <<= 1;
- TTHashMask |= 1;
- }
- HashSize = TTHashMask + 1;
- printf ("Adjusting HashSize to %d slots\n", HashSize);
- }
Initialize ();
/* Default to enable pondering */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Tidy up hashsize calculation,
Anil Mungal <=