mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -86,15 +86,6 @@ public class Number128 extends Number implements Comparable<Number128>{
|
||||
this.leastSigBits = leastSigBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取高低位数组,long[0]:低位,long[1]:高位
|
||||
*
|
||||
* @return 高低位数组,long[0]:低位,long[1]:高位
|
||||
*/
|
||||
public long[] getLongArray() {
|
||||
return getLongArray(ByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取高低位数组,规则为:
|
||||
* <ul>
|
||||
|
@@ -542,10 +542,9 @@ public class HashUtil {
|
||||
*
|
||||
* @param data 数据
|
||||
* @return hash值
|
||||
* @since 5.2.5
|
||||
*/
|
||||
public static long[] cityHash128(final byte[] data) {
|
||||
return CityHash.INSTANCE.hash128(data).getLongArray();
|
||||
public static Number128 cityHash128(final byte[] data) {
|
||||
return CityHash.INSTANCE.hash128(data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,11 +552,10 @@ public class HashUtil {
|
||||
*
|
||||
* @param data 数据
|
||||
* @param seed 种子
|
||||
* @return hash值,long[0]:低位,long[1]:高位
|
||||
* @since 5.2.5
|
||||
* @return hash值
|
||||
*/
|
||||
public static long[] cityHash128(final byte[] data, final Number128 seed) {
|
||||
return CityHash.INSTANCE.hash128(data, seed).getLongArray();
|
||||
public static Number128 cityHash128(final byte[] data, final Number128 seed) {
|
||||
return CityHash.INSTANCE.hash128(data, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,10 +574,10 @@ public class HashUtil {
|
||||
*
|
||||
* @param data 数据
|
||||
* @param seed 种子
|
||||
* @return hash值,long[0]:低位,long[1]:高位
|
||||
* @return hash值
|
||||
*/
|
||||
public static long[] metroHash128(final byte[] data, final long seed) {
|
||||
return MetroHash128.of(seed).hash128(data).getLongArray();
|
||||
public static Number128 metroHash128(final byte[] data, final long seed) {
|
||||
return MetroHash128.of(seed).hash128(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -135,7 +135,7 @@ public class MetroHash128Test {
|
||||
@Test
|
||||
public void metroHash128GetLongArrayTest() {
|
||||
final byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
|
||||
final long[] hash128 = MetroHash128.of(0).hash128(str).getLongArray();
|
||||
final long[] hash128 = MetroHash128.of(0).hash128(str).getLongArray(ByteOrder.BIG_ENDIAN);
|
||||
Assertions.assertEquals(228255164667538345L, hash128[0]);
|
||||
Assertions.assertEquals(-6394585948993412256L, hash128[1]);
|
||||
}
|
||||
|
@@ -13,16 +13,17 @@
|
||||
package org.dromara.hutool.core.util;
|
||||
|
||||
import org.dromara.hutool.core.codec.hash.HashUtil;
|
||||
import org.dromara.hutool.core.util.ByteUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class HashUtilTest {
|
||||
|
||||
@Test
|
||||
public void cityHash128Test(){
|
||||
final String s="Google发布的Hash计算算法:CityHash64 与 CityHash128";
|
||||
final long[] hash = HashUtil.cityHash128(ByteUtil.toUtf8Bytes(s));
|
||||
final long[] hash = HashUtil.cityHash128(ByteUtil.toUtf8Bytes(s)).getLongArray(ByteOrder.BIG_ENDIAN);
|
||||
Assertions.assertEquals(0x5944f1e788a18db0L, hash[0]);
|
||||
Assertions.assertEquals(0xc2f68d8b2bf4a5cfL, hash[1]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user