gpt4 book ai didi

hash - 大查询 : Hashing a String Doesn't Match CityHash

转载 作者:行者123 更新时间:2023-12-01 11:33:46 28 4
gpt4 key购买 nike

试图让我的外部 CityHash 返回与 BigQuery Hash() 相同的值。以下是我要匹配的值: BigQuery Hash Examples

唯一匹配的散列字符串是空字符串。

BigQuery Query Reference ,它提到它使用 CityHash 库。我试过为 CityHash 使用多个外部库,它们彼此一致,但与 BigQuery Hash() 不一致

这是 Go (Golang) 中的 CityHash 示例:

package main

import (
"fmt"

"bitbucket.org/creachadair/cityhash"
)

func main() {
var bytesToHash = []byte("mystringtohash")

myHash := int64(cityhash.Hash64(bytesToHash))
fmt.Printf("Hashed version of '%s': %d\n", bytesToHash, myHash)

bytesToHash = []byte("")
myHash = int64(cityhash.Hash64(bytesToHash))
fmt.Printf("Hashed version of '%s': %d\n", bytesToHash, myHash)
}

这是我程序的输出:

Hashed version of 'mystringtohash': -6615946700494525143
Hashed version of '1234': 882600748797058222
Hashed version of '': -7286425919675154353

BigQuery 是否在对字符串进行哈希处理之前对其进行了特殊处理?

最佳答案

好的,我花了一些时间检查代码,这就是我认为发生的情况。

不幸的是,这些版本自 1.1 版以来似乎不兼容,如 README 中所述(重点是我的):

CityHash v1.1, October 22, 2012

  • Add CityHash32(), intended for 32-bit platforms.
  • Change existing functions to improve their hash quality and/or speed. > Most of the changes were minor, but CityHashCrc* was substantially reworked (and made perhaps 10% slower, unfortunately).
  • Improve README.

我不确定在这里做什么是正确的,也许 BigQuery 应该更新其实现以匹配版本 1.1.1,或者这对依赖它的现有用户来说可能是一个重大变化。但至少我们知道现在发生了什么。

关于hash - 大查询 : Hashing a String Doesn't Match CityHash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29710461/

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