gpt4 book ai didi

c# - xxHash 转换导致散列太长

转载 作者:行者123 更新时间:2023-11-30 13:55:57 28 4
gpt4 key购买 nike

我正在使用 C# 的 xxHash 来对值进行散列以确保一致性。ComputeHash 返回一个 byte[],但我需要将结果存储在一个 long 中。

我可以使用 BitConverter 将结果转换为 int32。这是我尝试过的:

var xxHash = new System.Data.HashFunction.xxHash();
byte[] hashedValue = xxHash.ComputeHash(Encoding.UTF8.GetBytes(valueItem));
long value = BitConverter.ToInt64(hashedValue, 0);

当我使用 int 时它工作正常,但是当我更改为 ToInt64 时它失败了。

这是我得到的异常:

Destination array is not long enough to copy all the items in the collection. Check array index and length.

最佳答案

当你构造你的xxHash对象时,你需要提供一个hashsize:

var hasher = new xxHash(32);

有效的散列大小为 32 和 64。

参见 https://github.com/brandondahler/Data.HashFunction/blob/master/src/xxHash/xxHash.cs来源。

关于c# - xxHash 转换导致散列太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com