cppweeklynews icon indicating copy to clipboard operation
cppweeklynews copied to clipboard

171

Open wanghenshui opened this issue 3 months ago • 0 comments

How useful is the hint passed to the std::unordered_… collections? https://devblogs.microsoft.com/oldnewthing/20241028-00/?p=110428

emplace_hit 在有序map有很大作用,但是在无序容器,由于不允许重复,hint基本没啥用

但无序容器存在允许重复值的 multixx,这种场景可以用,一般来说用不着

总结了一个表格

实现 unordered_multixx unordered_xx
是否允许重复
msvc/STL 如果匹配就是用 如果匹配就使用
clang/libcxx 忽略 如果匹配就使用
gcc/libstdc++ (large or fast) 忽略 如果匹配就使用
gcc/libstdc++ (small and slow) 忽略 使用

libstdc++针对不同key的hash有快慢识别,默认是快的 (long double慢) 这里有坑不知道大家记得不

wanghenshui avatar Oct 29 '24 07:10 wanghenshui