当前位置:网站首页>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 .
边栏推荐
- 【解惑】App处于前台,Activity就不会被回收了?
- Audio device strategy audio device output and input selection is based on 7.0 code
- Cartoon | who is the first ide in the universe?
- 基于PyTorch利用CNN对自己的数据集进行分类
- Main work of digital transformation
- 测试3个月,成功入职 “字节”,我的面试心得总结
- [OKR target management] case analysis
- yolo训练过程中批量导入requirments.txt中所需要的包
- Pytorch中自制数据集进行Dataset重写
- [deep learning] 3 minutes introduction
猜你喜欢
深度学习机器学习各种数据集汇总地址
zdog. JS rocket turn animation JS special effects
textSwitch文本切换器的功能和用法
MRS离线数据分析:通过Flink作业处理OBS数据
手机版像素小鸟游js戏代码
DatePickerDialog和trimepickerDialog
Alertdialog create dialog
DatePickerDialog and trimepickerdialog
第3章业务功能开发(用户访问项目)
[4500 word summary] a complete set of skills that a software testing engineer needs to master
随机推荐
漫画 | 宇宙第一 IDE 到底是谁?
How to implement safety practice in software development stage
MRS离线数据分析:通过Flink作业处理OBS数据
机器视觉(1)——概述
imageswitcher的功能和用法
Show progress bar above window
Audio device strategy audio device output and input selection is based on 7.0 code
js拉下帷幕js特效显示层
【TPM2.0原理及应用指南】 1-3章
第2章搭建CRM项目开发环境(数据库设计)
线上比赛相关规则补充说明
Taffydb open source JS database
在窗口上面显示进度条
Based on pytorch, we use CNN to classify our own data sets
swiper左右切换滑块插件
notification是显示在手机状态栏的通知
第1章CRM核心业务介绍
科学家首次观察到“电子漩涡” 有助于设计出更高效的电子产品
2021-06-28
Pro2: modify the color of div block