qHash 跨计算机一致吗?
我有一个包含多个文本列的数据库表,这些文本列总体上必须是唯一的,并且我不想使用多列键,因此我正在考虑将字符串一起哈希为 int 并将其用作主键。我想知道利用 uint qHash ( const QString & key ),或者编写我自己的函数,因为数据库需要由不同地方的不同人编辑。 (另外,如果整个方法不好,请帮忙。)
I have a database table with multiple text columns that collectively have to be unique, and I don't want to use a multicolumn key, so I was thinking to hash the strings together into an int and use that as the primary key. I was wondering if it would be a better idea to take advantage of uint qHash ( const QString & key ), or to write my own function, given that the database will need to be edited by different people in different places. (Also, if the whole approach is bad, please help.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
qHash 的实现如下:
该代码中没有任何特定于平台的内容。然而,哈希算法并不能像数据库那样保证唯一性。它会尽力避免碰撞,但不能保证。这就是大多数哈希容器使用存储桶和重新分配算法的原因。
qHash is implemented as below :
There is nothing specific to platform in that code. However a hash algorithm does not guarantee uniqueness like a database. It does its best to avoid collisions but it is not guaranteed. That is why most hash containers use buckets and reallocation algorithms.