当前位置:网站首页>Hash (hash)
Hash (hash)
2022-07-27 04:20:00 【0zien0】
One . Hash function (Hash function)
meaning :
Put any length of input , Extract data summary , It is converted into fixed length output by hash algorithm .
characteristic :
1. The hash values are different , Then the input content must be different .
2. The hash has the same value , The values entered are not necessarily the same ( There is hash collision ).
3. The value of the hash is irreversible ( The original input cannot be derived from the hash value )
Hash Algorithm :
Hash The algorithm has no fixed formula , Any algorithm that conforms to the hash idea can be called Hash Algorithm .MD5 and SHA-1 It can be regarded as the most widely used Hash The algorithm .
MD5 It is widely used to verify data integrity , Such as : After downloading the file , You can generate a copy of MD5 File and source file MD5 comparing , If it's the same , The document is considered complete , otherwise , It may be because the download is missing 、 The data has been modified, which leads to the inconsistency between the downloaded file and the source file .
PS: Little knowledge , Even if it's MD5 Hash collision also occurs , However, the probability is extremely low, and it is difficult to make the hash values consistent by modifying the data manually ~ So basically, it can be considered MD5 The verification is accurate . If extremely high accuracy is required , If you don't want any hash collision possible , The source file can be processed once MD5 Get hash value A, Then do another test on the source file SHA-1 Get hash value B, And then A and B Connect and do it again MD5, By combining MD5 and SHA-1 To get the verification result , It should be highly accurate ~
Two . Hashtable (Hash table)
Array : Reading data is fast , The efficiency of adding and deleting data is very low .
Linked list : The efficiency of adding and deleting data is very high , The speed of readable data is very slow .
Hashtable : I think it's a combination of array and linked list , Reading and writing can have higher efficiency .
Workflow of hash table :
1. The user enters a set of key value pairs {key, value} data .
2. Use hash Function on user input key To deal with F(key).
3. adopt F(key) The value in the corresponding storage location is directly obtained from the processing result of .PS: You don't need to traverse one by one , Get value directly .
4. If the value in the corresponding position is empty , Put it directly in value that will do .
Hash collision :
The fourth step of the above workflow , Once there is a value in the corresponding position , And this value corresponds to key Not equal to the current user input key, Hash collision occurs . Because of different input sources (key) after Hash It is possible to generate the same hash value after function processing .
There are many ways to deal with hash collisions , Take it here hashmap As a solution ( I think his plan is very good ~). When we save data, we can save data in the form of linked list , When a hash conflict occurs , Just traverse the linked list , See if there are any similarities key Of , Cover if you have , Just add this new set of data at the end of the linked list . Then in order to speed up the search , When the number of linked lists is greater than 8 Time , We can convert the linked list into a red black tree .
PS: Even if hash collision occurs , Ideally, it is still evenly distributed under each hash value , If some hash values collide too many times , Resulting in uneven distribution , At this time, the efficiency of hash table becomes low , Nor is it the result we want , Consider a different hash algorithm .
边栏推荐
- What is animation effect? What is the transition effect?
- scala 不可变Map 、 可变Map 、Map转换为其他数据类型
- Introduction to JVM principle
- 每日一题:奇偶树
- Subject 3: Jinan Zhangqiu line 3
- JMeter学习笔记004-CSV文件行数控制循环次数
- PX4模块设计之十二:High Resolution Timer设计
- 2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作
- 288页18万字智能化校园总体设计 目录
- C how to set different text watermarks for each page of word
猜你喜欢

Five basic data structures of redis

288 page 180000 word intelligent campus overall design directory
![[MySQL series] MySQL index transactions](/img/85/04eb67471ba1348af2a26bc4621c65.png)
[MySQL series] MySQL index transactions

11. Zuul routing gateway

Towhee weekly model

ArrayList与LinkedList区别

Rust:axum learning notes (1) Hello World

【小样本分割】MSANet: Multi-Similarity and Attention Guidance for Boosting Few-Shot Segmentation

288页18万字智能化校园总体设计 目录
![Abstract intelligent extraction [based on Bert technology]](/img/1c/7c1b0e9bc9af62308f4124104f6110.png)
Abstract intelligent extraction [based on Bert technology]
随机推荐
tcp协议知识详解
js实现页面跳转与参数获取加载
ArrayList与LinkedList区别
Introduction to JVM principle
【OBS】circlebuf
php+swoole
网工知识角|只需四个步骤,教会你使用SecureCRT连接到eNSP,常用工具操作指南必看
每日一题:从链表中删去总和值为零的连续节点
零基础小白也能懂的 Redis 数据库,手把手教你易学易用!
influxDB 基础了解
2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作
Principle of bean validation --07
What is the principle difference between lateinit and lazy in kotlin
PSINS工具箱中轨迹生成工具详细解析
CloudCompare&PCL 匹配点中值(或标准差)距离抑制
Abstract intelligent extraction [based on Bert technology]
c# 获取uuid
ffmpeg合并视频功能
JMeter download and installation
Stm32cubemx learning notes (41) -- eth interface +lwip protocol stack use (DHCP)