开发者

java string hash function with avalanche effect

开发者 https://www.devze.com 2023-02-10 11:53 出处:网络
In testing with String.hashCode() I notic开发者_运维知识库ed that it does not have an avalanche effect. I know that there\'s a java port of Jenkins hash, but I was wondering if there\'s a hash functio

In testing with String.hashCode() I notic开发者_运维知识库ed that it does not have an avalanche effect. I know that there's a java port of Jenkins hash, but I was wondering if there's a hash function, maybe in some apache library or something, that has this property.

Edit: I'm looking for a function that exhibits this property, and returns a 32-bit (or 64-bit) integer (for example, like Jenkins hash). I'm not using it for cryptography, and I'm not intending to replace String.hashCode in general. I just thought hashCode had this property, and it turns out it doesn't, and I'm wondering if there's anything in java's standard libs or maybe an apache lib, that satisfies my need.


The avalanche effect, as described in the wikipedia page you linked to, is an important property of cryptographic hash functions. String.hashCode() is not a cryptographic hash function. Its only goal is to generate sufficiently distributed hash codes for different strings so that HashMap, HashSet and all other hash-based collections are efficient when holding strings.

For cryptographic hash functions, look at JCA, which allows generating SHA-1, MD5, and other cryptographic digests, which all have the effect you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消