/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating(Iterable<HashFunction> hashFunctions) { checkNotNull(hashFunctions); // We can't use Iterables.toArray() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); for (HashFunction hashFunction : hashFunctions) { list.add(hashFunction); } checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size()); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
/** * Returns a general-purpose, <b>non-cryptographic-strength</b>, streaming hash function that * produces hash codes of length at least {@code minimumBits}. Users without specific * compatibility requirements and who do not persist the hash codes are encouraged to * choose this hash function. * * <p><b>Warning: the implementation is unspecified and is subject to change.</b> * * @throws IllegalArgumentException if {@code minimumBits} is not positive */ public static HashFunction goodFastHash(int minimumBits) { int bits = checkPositiveAndMakeMultipleOf32(minimumBits); if (bits == 32) { return murmur3_32(); } else if (bits <= 128) { return murmur3_128(); } else { // Join some 128-bit murmur3s int hashFunctionsNeeded = (bits + 127) / 128; HashFunction[] hashFunctions = new HashFunction[hashFunctionsNeeded]; for (int i = 0; i < hashFunctionsNeeded; i++) { hashFunctions[i] = murmur3_128(i * 1500450271 /* a prime; shouldn't matter */); } return new ConcatenatedHashFunction(hashFunctions); } }
/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating(Iterable<HashFunction> hashFunctions) { checkNotNull(hashFunctions); // We can't use Iterables.toArray() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); for (HashFunction hashFunction : hashFunctions) { list.add(hashFunction); } checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size()); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating(Iterable<HashFunction> hashFunctions) { checkNotNull(hashFunctions); // We can't use Iterables.toArray() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); for (HashFunction hashFunction : hashFunctions) { list.add(hashFunction); } checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size()); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating( HashFunction first, HashFunction second, HashFunction... rest) { // We can't use Lists.asList() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); list.add(first); list.add(second); list.addAll(Arrays.asList(rest)); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
/** * Returns a hash function which computes its hash code by concatenating the hash codes of the * underlying hash functions together. This can be useful if you need to generate hash codes of a * specific length. * * <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash * functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}. * * @since 19.0 */ public static HashFunction concatenating( HashFunction first, HashFunction second, HashFunction... rest) { // We can't use Lists.asList() here because there's no hash->collect dependency List<HashFunction> list = new ArrayList<>(); list.add(first); list.add(second); list.addAll(Arrays.asList(rest)); return new ConcatenatedHashFunction(list.toArray(new HashFunction[0])); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);
hashFunctions[i] = murmur3_128(seed); return new ConcatenatedHashFunction(hashFunctions);