C++ 如何从3个有序整数创建哈希?
假设我有一个这样的结构C++ 如何从3个有序整数创建哈希?,c++,hash,C++,Hash,假设我有一个这样的结构 struct point3d{ int x; int y; int z; }; 如何从该结构创建哈希值? 谢谢这在很大程度上取决于你想要实现什么以及你需要多少分销 大多数非加密散列类似于: int64_t Hash(const point3d & point){ int64_t start = 1234; //magic number int64_t multiplier = 3467; //some other
struct point3d{
int x;
int y;
int z;
};
如何从该结构创建哈希值?
谢谢这在很大程度上取决于你想要实现什么以及你需要多少分销 大多数非加密散列类似于:
int64_t Hash(const point3d & point){
int64_t start = 1234; //magic number
int64_t multiplier = 3467; //some other magic number
int64_t hash = start + point.x;
hash = hash*multiplier + point.y;
hash = hash * multiplier + point.z;
return hash;
}
通过调整
start
和multiplier
在您的数据集上测试这一点,请查看,尤其是和。还有。最后,不要忘记如何创建。重新打开。所谓的dupe用于std::size\u t
,而不是int
。后者对溢出和位移位有限制。你说的“有序整数”是什么意思?@MatthieuBrucher:Oops。没有人是完美的。@Bathsheba不用担心;)