【发布时间】:2021-08-06 11:32:09
【问题描述】:
我正在尝试连接(不添加)2 个 uint16_t 结构成员和 2 个 uint32_t 结构成员,并将结果分配给 const void *p 以进行散列。我尝试实现的struct和concatenation函数如下。
struct xyz {
....
uint32_t a;
uint32_t b;
....
uint16_t c;
uint16_t d;
....
}
const void *p=concatenation(xyz.a,xyz.b,xyz.c,xyz.d)
已编辑:
我必须使用预定义的哈希函数。最适合我的任务的哈希函数似乎是这个。
uint32_t hash(const uint32_t p[], size_t n)
{
//Returns the hash of the 'n' 32-bit words at 'p'
}
或
uint32_t hash64(const uint64_t p[], size_t n)
{
//Returns the hash of the 'n' 64-bit words at 'p'
}
【问题讨论】:
-
如何你想连接?对齐应该是什么?
concatenation应该返回什么?谁拥有记忆?哈希函数如何知道p的数据类型,即它应该如何工作?为什么xyz没有std::hash专业化? -
在这种情况下“连接”是什么意思。您想让 0x01 与 0x02 “连接”为 0x0102 吗?请澄清你的问题!如果是这样,(void*) 就不能保留具有这种可变大小的值!
-
等等?这是任务?而教授希望将哈希函数的结果放入
void*???
标签: c++ pointers struct concatenation