Author: Heiner Marxen
Date: 09:07:36 07/14/01
Go up one level in this thread
On July 14, 2001 at 11:54:17, Miguel A. Ballicora wrote:
>On July 14, 2001 at 10:29:38, Heiner Marxen wrote:
>
>>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
>>
>>You could make value the highest part of the new integer, instead of
>>the lowest. Then extaction via >> should preserve the sign as long as
>>the value fits into the new integer.
>
>This is a cool idea! however, the extraction with >> is not guaranteed to
>be correct by the ANSI standard. It is implementation defined.
Sadly, this is true. I should have mentioned this, sorry. :-((
>Anyway, I believe that will be correct most of the time but I think is
>kind of risky.
Yes, most implementations will do it the way we want it to be.
You can implement a minimal plausibility test at run time, such as:
if( ((-5 << 8) >> 8) != -5 ) panic("cannot >> signed");
This will still not establish any real guarantee, but will catch most
implementations which do it otherwise.
If this still appears to be too unsecure, the signed value to pack into part
of an integer first has to be converted to some unsigned quantity,
and converted back when extracting. That way you can write it 100% portably,
at the expense of slightly less efficient code.
[ Of course, details of such coding/decoding should be hidden by some macros. ]
Regards,
Heiner
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.