问题描述
考虑到 comparer、hasher 和 allocator 是无状态的,rbtree
和 hashtable
的结构体应该是:
template</*...*/>
struct RBTree {
Node* header;
size_t count;
[[no_unique_address]] KeyComparer keyComparer;
[[no_unique_address]] KeyExtracter keyOf;
[[no_unique_address]] NodeAllocator nodeAlloc;
};
template</*...*/>
struct HashTable {
size_t* buckets;
Node* items;
size_t capacity;
size_t count;
size_t usedBucketCount;
[[no_unique_address]] KeyHasher keyHasher;
[[no_unique_address]] KeyExtracter keyOf;
[[no_unique_address]] NodeAllocator nodeAlloc;
};
static_assert(sizeof(RBTree</*...*/>) == 16);
static_assert(sizeof(HashTable</*...*/> == 40));
但实际上:
constexpr auto sizeOf_set = sizeof(std::set<double>);
// MSVC (std:c++ latest) Debug: 24
// MSVC (std:c++ latest) Release: 16
// clang 10.0.0 (-std=c++20) -O0,-O3: 48
constexpr auto sizeOf_unorderedSet = sizeof(std::unordered_set<double>);
// MSVC (std:c++ latest) Debug: 80
// MSVC (std:c++ latest) Release: 64
// clang 10.0.0 (-std=c++20) -O0,-O3: 56
对于rbtree
,MSVC(发布)的结果符合我的预期。 (但为什么 48 是叮当声???)
对于hashtable
,我完全糊涂了...
我想知道我是否遗漏了一些必要的东西......
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)