HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[this.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); }
public static HashCode combineOrdered(Iterable<HashCode> hashCodes) { Iterator<HashCode> iterator = hashCodes.iterator(); Preconditions.checkArgument(iterator.hasNext(), "Must be at least 1 hash code to combine."); int bits = ((HashCode) iterator.next()).bits(); byte[] resultBytes = new byte[bits / 8]; for (HashCode hashCode : hashCodes) { byte[] nextBytes = hashCode.asBytes(); Preconditions.checkArgument( nextBytes.length == resultBytes.length, "All hashcodes must have the same bit length."); for (int i = 0; i < nextBytes.length; i++) { resultBytes[i] = ((byte) (resultBytes[i] * 37 ^ nextBytes[i])); } } return HashCode.fromBytesNoCopy(resultBytes); }
public static HashCode combineUnordered(Iterable<HashCode> hashCodes) { Iterator<HashCode> iterator = hashCodes.iterator(); Preconditions.checkArgument(iterator.hasNext(), "Must be at least 1 hash code to combine."); byte[] resultBytes = new byte[((HashCode) iterator.next()).bits() / 8]; for (HashCode hashCode : hashCodes) { byte[] nextBytes = hashCode.asBytes(); Preconditions.checkArgument( nextBytes.length == resultBytes.length, "All hashcodes must have the same bit length."); for (int i = 0; i < nextBytes.length; tmp102_100++) { int tmp102_100 = i; byte[] tmp102_99 = resultBytes; tmp102_99[tmp102_100] = ((byte) (tmp102_99[tmp102_100] + nextBytes[tmp102_100])); } } return HashCode.fromBytesNoCopy(resultBytes); }
@Override public HashCode hash() { return HashCode.fromBytesNoCopy(bytes()); }