Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Opening book

Author: Andrew Williams

Date: 01:26:40 04/04/99

Go up one level in this thread


On April 04, 1999 at 01:46:39, Frank Phillips wrote:

>On April 01, 1999 at 15:56:14, Andrew Williams wrote:
>
>>On April 01, 1999 at 14:37:51, Frank Phillips wrote:
>>
>>>I have added an opening book to my developing program and am wondering about
>>>better ways of storing the information.  At the moment I store opening positions
>>>as a hash-table in a disk file, accessing them as I would a hash table stored in
>>>RAM by shifting the hash code for  the appropriate number of places to generate
>>>the index and then performing a lookup as
>>>fseek(pfile,index*sizeof(record),SEEK_SET)  etc.  This works but involves a lot
>>>of wasted storage.  For example, I have a 12MB file of about 1million records
>>>with the order of only 100 000 book entries.  Is it normal having generated the
>>>book to then sort and search it as a simple linear file instead?  What do others
>>>do?
>>
>>In my program, I don't store blank entries. I simply store the entries that
>>exist and do a binary search on the file to see if the position is in the
>>book. The hash key is the same as the one used in the transposition table,
>>but I use it in a different way.
>>
>>Andrew
>
>Thanks.    I eventually used a quick sort function found on the internet which
>seems to work fine. As expected, my book size is now about a tenth of the one
>storing mainly zero.  There is also no noticeable, practical difference in speed
>of accessing via binary search compared to hashing.
>
>
>Initially I tried the MSVC 5 qsort() library function but could not work out how
>to use the  (compare) function with structures.
>
>qsort((void*) precord, records, sizeof(BookHashRecordT), compare);
>
>int __cdecl compare( const void *a, const void *b )
>{
>/*  The thing I want to sort on is in record.top32bits, where record is of type
>BookHashRecordT. */
>
>return( );
>}
>
>(precord is a pointer to the memory area storing the records.  records the
>number of records.).
>
>If anybody can enlighten me I would be interested.

Hi Frank,

I think it should look like this, but maybe I've misunderstood:

int __cdecl compare( const void *a, const void *b )
{
	/*	The thing I want to sort on is in record.top32bits, where record
		is of type BookHashRecordT.
	*/

	if(a->top32bits > b->top32bits) return 1;
	else if(a->top32bits == b->top32bits) return 0;
	else return -1;
}

Andrew



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.