当前位置:网站首页>取余操作是一个哈希函数
取余操作是一个哈希函数
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)
边栏推荐
- Fonction (sujette aux erreurs)
- Phpmailer reported an error: SMTP error: failed to connect to server: (0)
- [uniapp] system hot update implementation ideas
- How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
- 基于TCP的移动端IM即时通讯开发仍然需要心跳保活
- [Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
- [illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording
- 【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
- NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
- Rome chain analysis
猜你喜欢

Pyqt pyside custom telescopic menu bar sharing (including tutorial)

Threejs Internet of things, 3D visualization of farm (III) model display, track controller setting, model moving along the route, model adding frame, custom style display label, click the model to obt

Network layer - forwarding (IP, ARP, DCHP, ICMP, network layer addressing, network address translation)

How to realize real-time audio and video chat function

kubernetes集群之调度系统

Threejs rendering obj+mtl model source code, 3D factory model

Differences among 10 addressing modes

Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
![[phantom engine UE] package error appears! Solutions to findpin errors](/img/d5/6747e20da6a8a4ca461094bd27bbf0.png)
[phantom engine UE] package error appears! Solutions to findpin errors

How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
随机推荐
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
根据入栈顺序判断出栈顺序是否合理
Serpentine matrix
Machine learning -- neural network
Machine learning decision tree
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
A application wakes up B should be a fast method
【虚幻引擎UE】实现测绘三脚架展开动画制作
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
kubernetes集群之调度系统
MacBook安装postgreSQL+postgis
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
小程序中实现文章的关注功能
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
provide/inject
Seven join join queries of MySQL
SPI read / write flash principle + complete code
[thingsboard] how to replace the homepage logo
This is an age of uncertainty
Get to know MySQL connection query for the first time