How can i generate a long hash of a String?

后端 未结 4 2025
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 21:27

I have a java applciation in which I want to generate long ids for strings (in order to store those strings in neo4j). In order to avoid data duplication, I wou

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 21:53

    long has 64 bits. A String of length 9 has 72 bits. from pigeon hole principle - you cannot get a unique hashing for 9 chars long strings to a long.

    If you still want a long hash: You can just take two standard [different!] hash functions for String->int, hash1() and hash2() and calculate: hash(s) = 2^32* hash1(s) + hash2(s)

提交回复
热议问题