简体   繁体   中英

java string hash function with avalanche effect

In testing with String.hashCode() I noticed 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM