Hash value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimhce
    New Member
    • Aug 2007
    • 4

    Hash value

    Hi,

    I want to generate a hash key from a string, and I want to the hash key is the same value for the same string. But it turns out all the hash functions I have tried, generate different keys from the same string. For example, if I run an excusable hash function several times in following example, it gave me all different values even the string does not change:

    $ BobJenkinHash "hello"
    0x183B3443

    $ BobJenkinHash "hello"
    0x24082445

    Is it possible to generate the same hash value based on the same string?

    Thank you.

    Jim
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by jimhce
    Hi,

    I want to generate a hash key from a string, and I want to the hash key is the same value for the same string. But it turns out all the hash functions I have tried, generate different keys from the same string. For example, if I run an excusable hash function several times in following example, it gave me all different values even the string does not change:

    $ BobJenkinHash "hello"
    0x183B3443

    $ BobJenkinHash "hello"
    0x24082445

    Is it possible to generate the same hash value based on the same string?

    Thank you.

    Jim
    Have u heard about CRC, if yes then that can help u.
    Try to use 32-bit crc(the code for this is available in net).
    This will generate a unsigned long nu,ber for every input string u give.

    Raghuram

    Comment

    • jimhce
      New Member
      • Aug 2007
      • 4

      #3
      Could you point me the URL?

      Thank you.

      Jim

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Also, if your hash does result in the same value for multiple keys, you can use a chain-link table to handle this. That is, of your are not using a chain-link table already.

        Any hashing algorithm will produce the same value for multiple keys. The chain-link table is only way to handle the one-to-many relataionship. You can also use a vector of vectors.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by weaknessforcats
          Any hashing algorithm will produce the same value for multiple keys. The chain-link table is only way to handle the one-to-many relataionship.
          That is not true; hash functions exist that are 'perfect', i.e. for any different pair
          of keys k_i and k_j, h(k_i) != h(k_j); there even exist 'minimal perfect hash
          functions where h(x) in [1, |x|]; but the set of keys k_i has to be known in
          advance so h() can be computed.

          kind regards,

          Jos

          Comment

          Working...