예제 #1
0
 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);
 }
예제 #2
0
 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);
 }
예제 #3
0
 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());
 }