当前位置:网站首页>Tips of the week 136: unordered containers
Tips of the week 136: unordered containers
2022-07-07 17:58:00 【-Flying crane-】
TotW#136 Originally published in 2017 year 6 month 23 Japan
from Matt Kulukundis A literary creation
“ Sometimes , When the material is really good , You will place expectations on yourself , To make it the best program . You don't just provide hashes for rules , Go on with your work , Then go home .”- Peter . Dinlaki
Cut a long story short , About the latest official recommendations , Please have a look at https://abseil.io/docs/cpp/guides/container. This tip introduces new types , But it is not a normative reference .
Introduce absl:_hash_map
There is a new series of related containers in towns . They boast of improving efficiency and providing services earlier than C++17 The interview of . They also provide developers with direct control over their implementation and default hash functions , This is important for the long-term development of the code base . New code should prioritize these types over std::unordered_map. All in the system map and set With std::unordered_map same API, So it's easy to switch to them .
For each absl::_hash_map for , There is also a absl::_hash_set; however , These charts will only describe map The situation of , And what we often mention is map.
absl::flat_hash_map and absl::flat_hash_set
These should be your default choices . They store their value_type To the main array . Because when they scatter again, they move data , Element cannot make pointer stable . If you need pointer stability or your value is large , Please consider using absl::node_hash_map Instead of , perhaps Absl::flat_has-mak<Key,std::unique_ptr>.
absl::node_hash_map and absl::node_hash_set
Attention : Because it's hashing like map[“a”]=map[“b”] Then invalid memory will be accessed , Unstable pointer .
They are allocated outside the main array value_type( Such as std::unordered_map). Because of these independent distributions , They provide pointer stability for stored data ( Stored in map The address of the object in does not change ), And the empty slot only needs 8 Bytes . in addition , They can store things that can neither be moved nor copied .
We usually recommend that you use absl::flat_hash_map<K, std::unique_ptr> instead of absl::node_hash_map<K, V>, about node_hash_set So it is with .
边栏推荐
- Click on the top of today's headline app to navigate in the middle
- Face recognition attendance system based on Baidu flying plasma platform (easydl)
- 青年时代历练和职业发展
- Deep learning - make your own dataset
- imageswitcher的功能和用法
- Run Yolo v5-5.0 and report an error. If the sppf error cannot be found, solve it
- 【OKR目标管理】案例分析
- 在窗口上面显示进度条
- 【解惑】App处于前台,Activity就不会被回收了?
- Pro2: modify the color of div block
猜你喜欢
Pytorch中自制数据集进行Dataset重写
企业经营12法的领悟
Deep learning machine learning various data sets summary address
Mrs offline data analysis: process OBS data through Flink job
List selection JS effect with animation
zdog.js火箭转向动画js特效
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
第3章业务功能开发(实现记住账号密码)
带动画的列表选中js特效
Introduction to OTA technology of Internet of things
随机推荐
Create dialog style windows with popupwindow
Interviewer: why is the page too laggy and how to solve it? [test interview question sharing]
Chapter 3 business function development (to remember account and password)
Tips for this week 134: make_ Unique and private constructors
Functions and usage of imageswitch
如何在软件研发阶段落地安全实践
Dragging the custom style of Baidu map to the right makes the global map longitude 0 unable to be displayed normally
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决
Chapter 1 Introduction to CRM core business
Pro2:修改div块的颜色
Click on the top of today's headline app to navigate in the middle
4种常见的缓存模式,你都知道吗?
2021-06-28
本周小贴士131:特殊成员函数和`= default`
Based on pytorch, we use CNN to classify our own data sets
Supplementary instructions to relevant rules of online competition
在窗口上面显示进度条
[answer] if the app is in the foreground, the activity will not be recycled?
MRS离线数据分析:通过Flink作业处理OBS数据
In depth understanding of USB communication protocol