Hm.... what's the math behind this hashing method? I have some doubts if it's 
discrete hashing without a prime. If you square and shift numbers it's possible 
that a range of other numbers have the same result, or not ...?

I'm using Elf-hash for fulltext search. If your 12 digits are for descriptive 
purpous and one collision in 2147483647 is Ok then you're fine with the example 
below. If this isn't enough, you can split your 12 digits like Miro Pomsar said 
and compute a hash for each 6 digits with it.
In any case, I'd prefer a prime hashing function like Elf hash or others for 
this.

static Int32 ELFHash(Char* str, UInt32 len)
{

   UInt32 hash = 0;
   UInt32 x    = 0;
   UInt32 i    = 0;

   for(i = 0; i < len; str++, i++)
   {
      hash = (hash << 4) + (*str);
      if((x = hash & 0xF0000000L) != 0)
      {
         hash ^= (x >> 24);
         hash &= ~x;
      }
   }

   return (hash & 0x7FFFFFFF);
}


Regards
Benjamin



Miro Pomsar wrote:

>Hi,
>       you should really consider to convert the 12 digit string to a 64bit 
> struct
>like 
>typedef struct tagBigNum
>{
>       UInt32 hi; // first 6 digits
>       UInt32 lo ; // last 6 digits
>}
>       BigNum ;
>
>Holding an array of 12 byte strings would not be very effective (#items x 
>12bytes. You could also sort the BigNum array and use SysBinarySearch instead 
>of hashing. Anyway a good method for hashing numbers is to take the middle 
>bits of the square, eg.   (x*x >> 4) & 0xFFFF. You could do this for both hi 
>and lo and combine it to a long.
>
>On Sunday 29 May 2005 17:11, Katie A. (Moor) Siek wrote:
>
>>I'm trying to hash a string. It is a string of numbers, but the number
>>is 12 digits long - too big for a Int32.
>>
>>Thanks,
>>Katie
>>
>>On May 29, 2005, at 1:39 AM, Logan Shaw wrote:
>>
>>>Katie A. (Moor) Siek wrote:
>>>
>>>>Also, does anyone know a good hash function that works on Palms?
>>>
>>>Surely that would depend on what kind data you're trying to hash...
>>>
>>>Strings?  Floating point numbers?  Prime numbers?  RGB values?
>>>Pointers?
>>>
>>>  - Logan
>>>
>>>--
>>>For information on using the PalmSource Developer Forums, or to
>>>unsubscribe, please see http://www.palmos.com/dev/support/forums/
>>
>>*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*
>>Katie A. (Moor) Siek
>>PhD Candidate                         (812) 856-2107
>>Indiana University                            [EMAIL PROTECTED]
>>Computer Science Department         http://www.cs.indiana.edu/~ksiek
>>*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*
>
>


-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to