当前位置:网站首页>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 .
边栏推荐
- Tips of this week 135: test the contract instead of implementation
- Functions and usage of tabhost tab
- Taffydb open source JS database
- 深入浅出图解CNN-卷积神经网络
- TabHOST 选项卡的功能和用法
- 自动化测试:Robot FrameWork框架大家都想知道的实用技巧
- Import requirements in batches during Yolo training Txt
- Ansible 学习总结(9)—— Ansible 循环、条件判断、触发器、处理失败等任务控制使用总结
- YARN Capacity Scheduler容量调度器(超详细解读)
- Functions and usage of viewflipper
猜你喜欢

Chapter 3 business function development (safe exit)

仿今日头条APP顶部点击可居中导航

Functions and usage of viewswitch
![[4500 word summary] a complete set of skills that a software testing engineer needs to master](/img/82/acae52928b3ab48e9ecbf4ec436e5e.jpg)
[4500 word summary] a complete set of skills that a software testing engineer needs to master

百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示

自动化测试:Robot FrameWork框架大家都想知道的实用技巧

Test for 3 months, successful entry "byte", my interview experience summary

Deep learning machine learning various data sets summary address

带动画的列表选中js特效

Chapter 3 business function development (user access project)
随机推荐
actionBar 导航栏学习
Automated testing: a practical skill that everyone wants to know about robot framework
viewflipper的功能和用法
[distributed theory] (II) distributed storage
机器人工程终身学习和工作计划-2022-
Mysql 索引命中级别分析
MRS离线数据分析:通过Flink作业处理OBS数据
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决
Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
物联网OTA技术介绍
Simple loading animation
Functions and usage of tabhost tab
手机版像素小鸟游js戏代码
Audio device strategy audio device output and input selection is based on 7.0 code
Understanding of 12 methods of enterprise management
Explain it in simple terms. CNN convolutional neural network
[deep learning] 3 minutes introduction
Yarn capacity scheduler (ultra detailed interpretation)
Use onedns to perfectly solve the optimization problem of office network
js拉下帷幕js特效显示层