- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
uuid.h
(包:uuid-dev)是否有散列uuid_t
变量的函数?
如果它存在的话,使用它会比我自己滚动更好。如果没有函数,关于可以产生相对可靠的唯一结果的散列过程有什么建议吗?
#ifdef WIN32
#define GUID UUID
#define generateGUID UuidCreate // returns RPC_S_OK, RPC_S_UUID_LOCAL_ONLY, RPC_S_UUID_NO_ADDRESS
#define hashGUID(gUid) hash<long>()(gUid.Data1) ^ (hash<short>()(gUid.Data2) << 1) >> 1 ^ hash<short>()(gUid.Data3) << 1 ^ hash<char>()(gUid.Data4[0]) << 1
#else
#define GUID uuid_t
#define generateGUID uuid_generate_random
#define hashGUID(gUid) ???
#endif // WIN32
namespace std
{
template<>
struct hash<GUID>
{
std::size_t operator()(const GUID& gUid) const
{
using std::size_t;
using std::hash;
return hashGUID(gUid);
}
};
}
编辑 用法:在标准容器中作为键
std::unordered_map<GUID, Component> components;
最佳答案
由于您想对 UUID 进行哈希处理以便将它们存储在哈希表中,因此我建议采用一些简单的方法:
std::size_t operator()(const GUID& gUid) const
{
const uint64_t* half = reinterpret_cast<const uint64_t*>(&gUid);
return half[0] ^ half[1];
}
以上假定您使用的是 64 位平台(因此 uint64_t 与 size_t 一样宽)。
关于c++ - uuid_t 的现有哈希函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152892/
uuid.h(包:uuid-dev)是否有散列uuid_t变量的函数? 如果它存在的话,使用它会比我自己滚动更好。如果没有函数,关于可以产生相对可靠的唯一结果的散列过程有什么建议吗? #ifdef W
在 POSIX 中是否有空的 uuid_t 常量或可以返回空的 uuid_t 的函数? 我有一个函数应该在失败时返回一个空的 uuid_t,因此我需要生成/返回一个空的 uuid_t... uuid_
WinAPI UUID 分配后可以更改吗? Linux uuid_t 分配后可以更改吗? 例如(与UUID相关的示例,但对于uuid_t有同样的问题): class Component { publi
尝试在 Centos 2.6 上构建 vSphere Perl SDK。获得除一个以外的所有依赖项,即 UUID-0.05。 问题似乎是 uuid.h 包含文件引用 unistd.h 来定义 uuid
如何使用 Swift 将 UUID 传递给采用 uuid_t 的 C 函数? 假设我在桥接 header 中声明了以下函数: bool my_set_uuid(uuid_t uuid); 在 Swif
我正在 Fedora(版本 20)中安装 OpenDAP。 OpenDAP 依赖于 UUID,因此我安装了 uuid-devel 及其依赖项。当我编译OpenDAP时,遇到以下错误: DODSFilt
这是在 map 中提供唯一键的适当方式吗?换句话说, key 是由 uuid 中包含的唯一值生成的,还是由指向 uuid_t 结构的指针生成的?一个附带的问题,当我不关心容器内按键的排序时,是否有更高
我是一名优秀的程序员,十分优秀!