当前位置:网站首页>本周小贴士#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 也是如此。
边栏推荐
- 数值 - number(Lua)
- Pychart ide Download
- Rpcms method of obtaining articles under the specified classification
- 阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
- 到底有多二(Lua)
- Flask搭建api服务
- 【信息安全法律法规】复习篇
- With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
- Solidity函数学习
- The mail server is listed in the blacklist. How to unblock it quickly?
猜你喜欢

命令模式 - Unity
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial

【网络攻防原理与技术】第5章:拒绝服务攻击

【TPM2.0原理及应用指南】 9、10、11章

科普达人丨一文弄懂什么是云计算?

PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight

SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名

自定义View必备知识,Android研发岗必问30+道高级面试题

Skimage learning (1)

Matplotlib绘制三维图形
随机推荐
命令模式 - Unity
Rpcms method of obtaining articles under the specified classification
Jenkins发布uniapp开发的H5遇到的问题
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
Matplotlib绘制三维图形
Reflections on "product managers must read: five classic innovative thinking models"
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
Flask搭建api服务-SQL配置文件
【Seaborn】组合图表、多子图的实现
Sator launched Web3 game "satorspace" and launched hoobi
Pychart ide Download
L1-027 出租(Lua)
【TPM2.0原理及应用指南】 5、7、8章
【网络攻防原理与技术】第1章:绪论
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
Sator推出Web3游戏“Satorspace” ,并上线Huobi
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
如何在博客中添加Aplayer音乐播放器
L1-019 谁先倒(Lua)