use of com.google.common.hash.Hasher in project buck by facebook.
the class JsonObjectHashingTest method mapOrderDoesNotChangeHash.
@Test
public void mapOrderDoesNotChangeHash() {
Map<?, ?> map1 = ImmutableMap.of("firstKey", 24, "secondKey", new Float(13.5));
Map<?, ?> map2 = ImmutableMap.of("secondKey", new Float(13.5), "firstKey", 24);
Hasher hasher1 = Hashing.sha1().newHasher();
Hasher hasher2 = Hashing.sha1().newHasher();
JsonObjectHashing.hashJsonObject(hasher1, map1);
JsonObjectHashing.hashJsonObject(hasher2, map2);
assertEquals(hasher1.hash().toString(), hasher2.hash().toString());
}
use of com.google.common.hash.Hasher in project aerosolve by airbnb.
the class Util method getHashCode.
public static HashCode getHashCode(String family, String value) {
Hasher hasher = Hashing.murmur3_128().newHasher();
hasher.putBytes(family.getBytes());
hasher.putBytes(value.getBytes());
return hasher.hash();
}
use of com.google.common.hash.Hasher in project presto by prestodb.
the class TestTimeZoneKey method testZoneKeyData.
@Test
public void testZoneKeyData() throws Exception {
Hasher hasher = Hashing.murmur3_128().newHasher();
SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() {
@Override
public int compare(TimeZoneKey left, TimeZoneKey right) {
return Short.compare(left.getKey(), right.getKey());
}
}, TimeZoneKey.getTimeZoneKeys());
for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) {
hasher.putShort(timeZoneKey.getKey());
hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8);
}
// Zone file should not (normally) be changed, so let's make is more difficult
assertEquals(hasher.hash().asLong(), 5498515770239515435L, "zone-index.properties file contents changed!");
}
use of com.google.common.hash.Hasher in project torodb by torodb.
the class ObjectIdFactory method createMachineId.
private static int createMachineId() {
int machineId;
try {
Hasher hasher = Hashing.crc32c().newHasher();
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
boolean atLeastOne = false;
while (nics.hasMoreElements()) {
NetworkInterface ni = nics.nextElement();
if (ni != null) {
byte[] macAddress = ni.getHardwareAddress();
if (macAddress != null) {
for (byte b : macAddress) {
atLeastOne = true;
hasher.putByte(b);
}
}
}
}
if (!atLeastOne) {
LOGGER.warn("Failed to calculate the machine id. A random number is used");
machineId = new SecureRandom().nextInt();
} else {
machineId = hasher.hash().asInt();
}
} catch (SocketException ex) {
LOGGER.warn("Failed to calculate the machine id. A random number is used");
machineId = new SecureRandom().nextInt();
}
return machineId & 0xFFFFFF;
}
use of com.google.common.hash.Hasher in project gradle by gradle.
the class DefaultHashingClassLoaderFactory method calculateFilterSpecHash.
private static HashCode calculateFilterSpecHash(FilteringClassLoader.Spec spec) {
Hasher hasher = Hashing.md5().newHasher();
addToHash(hasher, spec.getClassNames());
addToHash(hasher, spec.getPackageNames());
addToHash(hasher, spec.getPackagePrefixes());
addToHash(hasher, spec.getResourcePrefixes());
addToHash(hasher, spec.getResourceNames());
addToHash(hasher, spec.getDisallowedClassNames());
addToHash(hasher, spec.getDisallowedPackagePrefixes());
return hasher.hash();
}
Aggregations