当前位置:网站首页>Principle and implementation of hash table, unordered set and mapping
Principle and implementation of hash table, unordered set and mapping
2022-07-23 21:35:00 【Adobee Chen】
Hashtable (Hash table) Also known as hash table , It's a way to get through key Data structure for direct access .
The hash table consists of two parts
- A data structure , Usually linked list 、 Array
- Hash function , Input key Return the index of the data structure
Example :
hash_table["lies"]=233 Example , Egos ASCII Code addition mod20 by Hash function

If anything else key after hash Function calculation is also placed in 9 The location of , Then it will happen hash Collision .
hash Collision refers to two different key Be calculated the same Hash result , Map complex information to small value ranges , Collision is inevitable , well Hash Function can reduce the probability of collision , Let the data be distributed as evenly as possible
Hashing is the most common collision solution
- Hash The function is still used to calculate the array subscript
- Each position of the array stores a header pointer of the linked list ( We call it the header array )
- Each linked list has the same Hash It's worth the data
Time complexity
expect : Insert 、 Inquire about 、 Delete O(1) --------- When the data distribution is relatively uniform
The worst : Insert 、 Inquire about 、 Delete O(N)----------- The data is all mapped to the same Hash When the value of
Set and map
aggregate (set) Store non repeating elements
- Ordered set , Sort by element size when convenient , Generally, balanced binary search tree is used to realize ,O(logN)
- unordered set , It's usually used hash Realization ,O(1)
mapping (map) Store keys (key) Non repeating key value pairs (key-value pair)
- Ordered mapping , When traversing, follow key Size sorting , Generally, balanced binary search tree is used to realize ,O(logN)
- Unordered mapping , Generally, hash table is used to realize ,O(1)
For language built-in types (int,string), There are already default excellent hash function , You can put it directly into set/map Use in
边栏推荐
- &9 nodemon自动重启工具
- h264编码参数
- How to implement desktop lyrics in pyqt
- 博客总排名为918
- Basic knowledge of mobile phone testing
- Tell me the top ten securities companies? Is it safe to open an account online?
- Detailed explanation of cesium events (mouse events, camera events, keyboard events, scene trigger events)
- Unity - 3D mathematics -vector3
- 分布式能源的不确定性——风速测试(Matlab代码实现)
- Jianzhi offer II 115. reconstruction sequence: topological sorting construction problem
猜你喜欢

Junior intern, ByteDance, after sharing, has been offered

Use Gaode map JS API 2.0 to load the starting and ending path tracks

寻找消失的类名

At 12 o'clock on July 23, 2022, the deviation from the top of the line of love life hour appeared, maintaining a downward trend and waiting for the rebound signal.

Improving performance with explicit rendering

CMake的学习

Kuberntes cloud native combat VI uses rook to build CEPH cluster

基于速度、复杂性等因素比较KernelSHAP和TreeSHAP

& 9 nodemon automatic restart tool

Scala programming (intermediate advanced experimental application)
随机推荐
Tell me the top ten securities companies? Is it safe to open an account online?
MySQL数据库索引
&9 nodemon自动重启工具
1309_ Add GPIO flip on STM32F103 and schedule test with FreeRTOS
2022.7.22 js对象
Basic principle of synchronized lock
SQLite database
Use code to set activity to transparent
SQLite数据库
Chapter 2 Regression
How to get the worker's hat? Where is the worker's helmet?
High numbers | calculation of double integral 3 | high numbers | handwritten notes
一时跳槽一时爽,一直跳槽一直爽?
Improving performance with explicit rendering
[create birthday card application]
Connect with Hunan Ca and use U_ Key login
2022.7.22 JS object
Protocol buffers 的问题和滥用
Basic syntax of MySQL DDL and DML and DQL
Complete set of official openlayers instances