summaryrefslogtreecommitdiffstats
path: root/config/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-09-16 09:08:30 +0200
committerHarald Musum <musum@yahooinc.com>2021-09-16 09:08:30 +0200
commit91af49f5ee0daf950407b8fe392bc52ed0275fb1 (patch)
tree9d1952edb1e172e070081feca1ef87e2226bc753 /config/src/main/java/com/yahoo
parent1a72eefec8a8c62f8b29455e15a4cc2d67eb4d0e (diff)
Test with xxhash64 as well
Diffstat (limited to 'config/src/main/java/com/yahoo')
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java47
1 files changed, 19 insertions, 28 deletions
diff --git a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
index 329661bf7ae..efad076d85c 100644
--- a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
+++ b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.util;
import com.yahoo.collections.Tuple2;
@@ -46,42 +46,18 @@ public class ConfigUtils {
private static final String doubleFormattedMax = new DecimalFormat("#.#").format(1e308);
private static final String doubleFormattedMin = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.ENGLISH)).format(-1e308);
- /**
- * Computes Md5 hash of a list of strings.
- *
- * @param payload a config payload
- * @return the Md5 hash of the list, with lowercase letters
- */
public static String getMd5(ConfigPayload payload) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- payload.serialize(baos, new JsonFormat(true));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return getMd5(baos.toByteArray());
+ return getMd5(getByteBuffer(payload));
}
- /**
- * Computes Md5 hash of a string.
- *
- * @param input the input String
- * @return the Md5 hash of the input, with lowercase letters
- */
- public static String getMd5(String input) {
- return getMd5(input.getBytes(StandardCharsets.UTF_8));
+ public static String getMd5(String input) {
+ return getMd5(ByteBuffer.wrap(input.getBytes(StandardCharsets.UTF_8)));
}
public static String getMd5(AbstractUtf8Array input) {
return getMd5(input.wrap());
}
- public static String getMd5(byte[] input) {
- MessageDigest md5 = getMd5Instance();
- md5.update(input);
- return HexDump.toHexString(md5.digest()).toLowerCase();
- }
-
public static String getMd5(ByteBuffer input) {
MessageDigest md5 = getMd5Instance();
md5.update(input);
@@ -105,6 +81,21 @@ public class ConfigUtils {
return Long.toHexString(hasher.hash(input, 0)).toLowerCase();
}
+ public static String getXxhash64(ConfigPayload payload) {
+ return getXxhash64(getByteBuffer(payload));
+ }
+
+ private static ByteBuffer getByteBuffer(ConfigPayload payload) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ payload.serialize(baos, new JsonFormat(true));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return ByteBuffer.wrap(baos.toByteArray());
+ }
+
+
/**
* Replaces sequences of spaces with 1 space, unless inside quotes. Public for testing;
*