当前位置:网站首页>取余操作是一个哈希函数
取余操作是一个哈希函数
2022-07-05 04:21:00 【蓝染k9z】
哈希
哈希有时候也被翻译为散列。
就是将任意长度的输入,通过哈希算法,压缩为某一固定长度的输出。
- 假如要快速读写100万条数据记录,要达到高速地存取,但是由于条件的限制,我们并没有能够容纳100万条记录的连续地址空间,该怎么办。
- 看看系统是否可以提供若干个较小的连续空间,而每个空间又能存放一定数量的记录。
- 比如我们找到了100个较小的连续空间。也就是说,这些空间彼此之间是被分隔开来的,但是内部是连续的,并足以容纳1万条记录连续存放,那么我们就可以使用余数和同余定理来设计一个散列函数,并实现哈希表的结构。

- 假设有两条记录,它们的记录标号分别是1和101.
- 我们把这些模100之后余数都是1的,存放到第1个可用空间里。
- 依此类推,将余数为2的2、102、202等,存放到第2个可用空间。
- 这样,我们就可以根据求余的快速数字变化,对数据进行分组,并把它们存放到不同的地址空间里。
- 而求余操作本身非常简单,因此几乎不会增加寻址时间。

为了增加数据散列的随机程度,可以在公式中加入一个较大的随机数MAX
在新的计算公式作用下,就会被分配到不同的可用空间中
使用了MAX这个随机数之后,被分配到同一个空间中的记录就更加“随机”,更适合需要将数据重新洗牌的应用场景,比如加密算法、MapReduce中的数据分发、记录的高速查询和定位等等。
加密
假设要加密一组三位数,那么设定一个这样的加密规则:
- 先对每个三位数的个、十和百位数,都加上一个较大的随机数。
- 然后将每位上的数都除以7,用所得的余数代替原有的个、十、百位数。
- 最后将第一位和第三位交换。
这就是一个基本的加密变换过程。
假如说,我们要加密625,随机数选择590127.
那百、十、个位分别加上这个随机数,就变成了590133 590129 590132,三位分别除以7求余后得到5 1 4。
最终得到的数字就是415。
如果加密的人知道加密的规则,那就可以算出原始的数据是625.
(提示:590127%7=6)
边栏推荐
- 北京程序员的真实一天!!!!!
- SPI read / write flash principle + complete code
- Basic analysis of IIC SPI protocol
- [untitled]
- [phantom engine UE] package error appears! Solutions to findpin errors
- Here comes the Lantern Festival red envelope!
- Threejs realizes rain, snow, overcast, sunny, flame
- Online sql to excel (xls/xlsx) tool
- [phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)
- 函數(易錯)
猜你喜欢

Pyqt pyside custom telescopic menu bar sharing (including tutorial)

指针函数(基础)

The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing

Behavior perception system

Sequence diagram of single sign on Certification Center

File upload bypass summary (upload labs 21 customs clearance tutorial attached)

技术教程:如何利用EasyDSS将直播流推到七牛云?

防护电路中的元器件

行为感知系统

How to get the first few pieces of data of each group gracefully
随机推荐
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
Threejs realizes sky box, panoramic scene, ground grass
Open graph protocol
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Basic analysis of IIC SPI protocol
函数(易错)
About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
Summary of scene design
Sword finger offer 04 Search in two-dimensional array
A solution to the problem that variables cannot change dynamically when debugging in keil5
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing
[Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
函数(基本:参数,返回值)
防护电路中的元器件
技术教程:如何利用EasyDSS将直播流推到七牛云?
Threejs Internet of things, 3D visualization of farms (II)
Three level linkage demo of uniapp uview u-picker components
学习MVVM笔记(一)
这是一个不确定的时代