当前位置:网站首页>Hash these knowledge you should also know
Hash these knowledge you should also know
2022-08-05 07:11:00 【code and thinking】
What is Hash
Hash is translated as hash in Chinese, and it is also called "hash". It is a general term for a class of functions.The input of any length (also known as pre-map, pre-image) is transformed into a fixed-length output through a hashing algorithm, and the output is the hash value.This transformation is a compressed map, that is, the space of the hash value is usually much smaller than the space of the input, and different inputs may hash to the same output, so it is impossible to determine the unique input value from the hash value.
Simply put, it is a function that compresses a message of any length into a message digest of a fixed length.
The role of Hash
hash is a function of compressing a message of any length into a message digest of a certain length.Equivalent to the fingerprint of a file.
Because the file is unlimited, the number of bits that can be represented by the mapped string is limited.Therefore, there may be different keys corresponding to the same Hash value.That's the possibility of a collision.
Hash storage data
The essence of the hash table is actually an array, and the key-value pair Entry is usually stored in the hash table.
The student number here is a key, and the hash table uses the hash function to calculate a value based on the key value. This value is the subscript value, which is used to determine where in the hash table the entry should be stored.
Hash collision solution
The solution to hash collision is open addressing method and zipper method.
Open addressing means that if the current array position 1 is occupied, it will be placed in the next position 2. If 2 is also occupied, it will continue to search until an empty position is found.
The zipper method uses a linked list. At this time, position 1 does not only store the Entry. At this time, the Entry also saves an additional next pointer, pointing to another position outside the array, and arranges Li Si in theHere, the next pointer in Zhang San's Entry points to Li Si's location, which is the stored memory address of this location.If there is still a conflict, put the conflicting Entry in a new position, and then Li Si's Entry points to it, thus forming a linked list.
Open addressing and zipping both try to find the next empty location to store the conflicting value.
Practical uses of Hash
Unique verification
- In java, it is used to judge whether the variables are equal and put into hashCode(), and together generate an integer that will not collide as much as possible
Data integrity verification:
- After downloading a file from the Internet, you can confirm whether the downloaded file is damaged by comparing the Hash value (such as MD5, SHA1) of the file.If the Hash value of the downloaded file is consistent with the Hash value given by the file provider, it proves that the downloaded file is intact
Quick Find:
- HashMap
Privacy Protection:
- When important data must be exposed, someone can choose to expose its Hash value (such as MD5) to ensure the security of the original data.For example, when logging in to a website, you can only save the hash value of the user's password. In each login verification, you only need to compare the hash value of the entered password with the hash value saved in the database. The website does not need to knowUser's password.In this way, when the website data is stolen, the user will not endanger the security of other websites because of the theft of their own password.
Author: Arrom
Link: https://juejin.cn/post/7127862424887099406
Source: Rare Earth Nuggets
边栏推荐
- HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
- 自媒体人一般会从哪里找素材呢?
- Promise (三) async/await
- DNSlog外带数据注入
- 技术分析模式(十)头肩图案
- 任务流调度工具AirFlow,,220804,,
- FPGA parsing B code----serial 4
- Flink Learning 11: Flink Program Parallelism
- 【instancetype类型 Objective-C】
- Rapid Medical's Ultra-Small and Only Adjustable Thromb Retriever Receives FDA Clearance
猜你喜欢
Shiny02---Shiny异常解决
IO process thread -> communication between processes -> day7
LabVIEW中如何实现任意形状的不规则按键
《PyTorch深度学习实践》第十一课(卷积神经网络CNN高级版)
共享内存+inotify机制实现多进程低延迟数据共享
Flink Learning 11: Flink Program Parallelism
Vulnhub靶机:HA_ NARAK
binary search tree problem
RNote108---Display the running progress of the R program
typescript61-泛型工具类型(pick)
随机推荐
Week 8 Document Clustering
共享内存+inotify机制实现多进程低延迟数据共享
Bluetooth gap protocol
【工具配置篇】VSCode 常用使用总结
PCI Pharma Services宣布斥资数百万美元扩建英国制造设施,以满足市场对支持肿瘤治疗的全球高效药制造服务日益增长的需求
Shared memory + inotify mechanism to achieve multi-process low-latency data sharing
访问被拒绝:“microsoft.web.ui.webcontrols”的解决办法
UDP group (multi)cast
re正则表达式
【Dynamic type detection Objective-C】
Freeswitch操作基本配置
2022杭电多校六 1006-Maex (树形DP)
(JLK105D)中山爆款LED恒流电源芯片方案
360度反馈调查表中的问题示范
矩阵的构造
Day9 of Hegong Daqiong team vision team training - camera calibration
Why does Mysql fail to create a database
开源中国活动合作说明书
一天学会从抓包到接口测试,通过智慧物业项目深度解析
17-VMware Horizon 2203 虚拟桌面-Win10 手动桌面池浮动(十七)