[futurebasic] RE: [FB] Fast lookups and jumps

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2002 : Group Archive : Group : All Groups

From: Jay <jktr@...>
Date: Wed, 24 Apr 02 20:44:05 -0500
>Does this mean shift the first four bytes right by the
>the length of the string then shift them, overwriting
>the zeroeth byte, leaving the bits left justified and
>all trailing bytes zeroed out.
>
>Thats my best interpretation of what I see.  Ow, my
>head hurts.
>
>myStringPtr.1&` >> ((4 - myStringPtr.0``) << 3)

this takes the 4 bytes after the length byte and shifts out any 
extraneous bytes, as indicated by the length byte. You would have had it, 
but may have missed the parentheses. (You have to read this line from the 
inside out.)

Here's a longhand version

fourChars&    = myStringPtr.1&`
strLen        = myStringPtr.0``
bytesToShift  = 4 - strLen 'How many extra bytes to get rid of?
bitsToShift   = bytesToShift << 3 'multiply by 8, fast way
theCode&      = fourChars >> bitsToShift 'Get rid of irrelevant bytes

If you have a 4-char string, bitsToShift will be 0
If you have a 3-char string, bitsToShift will be 8
If you have a 2-char string, bitsToShift will be 16
If you have a 1-char string, bitsToShift will be 24

This way, your CharCode is right-justified in the long int, meaning you 
can compare it directly to a value like _"XY".

Does that help?

BTW, I'd really like to see your list of codes. You know how I like 
making things fast. Let me take a shot.

 e-e
 =J= a  y
  "