Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: To compress hashtable size?

Author: Miguel A. Ballicora

Date: 10:23:56 07/14/01

Go up one level in this thread


On July 14, 2001 at 01:59:31, TEERAPONG TOVIRAT wrote:

>Hi,
>
>I've been trying to reduce my hashtable size,so that I can gain
>more entries. At first,I try to pack three structure tag into one
>integer it looks like this...
>
>  new integer = (flag<<a)|(depth<<b)|(value)
>
>It fails because value is signed int the rest are unsigned.
>Could anyone solve the problem?
>
>Thanks in advance,
>Teerapong

In general, it is suggested to be a bad idea to play with bits when both
unsigned and signed integers are involved. What I do is to convert value to
an unsigned number adding the abs(minimum value posibble). To extract it, I
substract this number. I have no idea if this is the most efficient way but
I figured that it was the safest for me. I do something like this:

/* assuming 16 bits used in value, long is 32 bits, valid values are
between -32767 and 32767 */
#define VALUE_MASK 0xffffu
#define CONV_CONSTANT (VALUE_MASK >> 1)
/* note: VALUE_MASK >> 1 ---> will be 32767 in this case
   so any valid value will be added CONV_CONSTANT and it will give a
   a valid number with no over flow */

unsigned long to_store, new_integer;

 to_store = (long int)value + CONV_CONSTANT; /* casting with (long int)
                                             avoid a wrong integral promotion*/
 new integer = (flag<<a)|(depth<<b)|(to_store);

To extract I do then:

   extracted = (long int)(new_integer & VALUE_MASK) - CONV_CONSTANT;

Regards,
Miguel




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.