当前位置:网站首页>本周小贴士#136:无序容器
本周小贴士#136:无序容器
2022-07-07 15:39:00 【-飞鹤-】
TotW#136最初发表于2017年6月23日
由Matt Kulukundis创作
“有时,当材料真的很好时,你会对自己寄予期望,以使其成为最好的节目。你不只是提供规则的哈希,接着做你的工作,然后回家。”-彼得.丁拉基
长话短说,有关官方最新的推荐,请看https://abseil.io/docs/cpp/guides/container。本贴士介绍新类型,但不是规范的参考。
介绍absl:_hash_map
城镇出现了一个新的关联容器系列。他们自夸提高效率并提供早于C++17的访问。他们也对开发者提供直接控制其实现和默认的哈希函数,这对于代码库的长远发展是重要的。新代码应该优先这些类型而不是std::unordered_map。在该系统中的所有map和set有与std::unordered_map相同的API,所以很容易转换到它们。
对于每个absl::_hash_map而言,这里同样也有一个absl::_hash_set;但是,这些图表将只描述map的情况,并且我们也常提到的只是map。
absl::flat_hash_map 和 absl::flat_hash_set
这些应该是你的默认选择。他们存储他们的value_type到主数组中。因为当它们重新散时移动数据,元素无法使得指针稳定。如果你需要指针稳定或者你的值很大,请考虑使用absl::node_hash_map代替,或者 Absl::flat_has-mak<Key,std::unique_ptr>。
absl::node_hash_map 和 absl::node_hash_set
敬告:因为在重新散列像map[“a”]=map[“b”]之后将访问无效的内存,指针不稳定。
它们主数组之外分配它们的value_type(如std::unordered_map)。由于这些独立的分配,它们为存储的数据提供指针稳定性(存储在map中的对象的地址不会改变),并且空槽只需要8个字节。另外,它们能够存储既不能移动也不能复制的东西。
我们通常建议您使用 absl::flat_hash_map<K, std::unique_ptr> 而不是 absl::node_hash_map<K, V>,对于 node_hash_set 也是如此。
边栏推荐
- 让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
- [Huang ah code] Why do I suggest you choose go instead of PHP?
- 【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
- Solidity 开发环境搭建
- 服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
- 智慧物流平台:让海外仓更聪明
- 【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
- LeetCode 535(C#)
- 【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
- Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
猜你喜欢
命令模式 - Unity
LeetCode刷题day49
SlashData开发者工具榜首等你而定!!!
如何在博客中添加Aplayer音乐播放器
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
redis主从、哨兵主备切换搭建一步一步图解实现
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
随机推荐
LeetCode 1986. The minimum working time to complete the task is one question per day
【黄啊码】为什么我建议您选择go,而不选择php?
Solidity 开发环境搭建
防火墙系统崩溃、文件丢失的修复方法,材料成本0元
How to choose the appropriate automated testing tools?
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
The top of slashdata developer tool is up to you!!!
[source code interpretation] | source code interpretation of livelistenerbus
Reflections on "product managers must read: five classic innovative thinking models"
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
Devops' operational and commercial benefits Guide
DNS series (I): why does the updated DNS record not take effect?
A tour of grpc:03 - proto serialization / deserialization
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
Nerf: the ultimate replacement for deepfake?
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
【TPM2.0原理及应用指南】 12、13、14章
状态模式 - Unity(有限状态机)
MySQL usage notes 1