当前位置:网站首页>h = key. Hashcode()) ^ (H > > 16) detailed explanation and why the hashcode value should be shifted to the right by 16 bits and XOR with the original hashcode value
h = key. Hashcode()) ^ (H > > 16) detailed explanation and why the hashcode value should be shifted to the right by 16 bits and XOR with the original hashcode value
2022-06-22 06:10:00 【Xiaoshuang is handsome enough to drag the Internet speed】
h = key.hashCode()) ^ (h >>> 16) Detailed interpretation
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
At present key = “java” Of hashCode() = 3254818 It's in decimal

Decimal system :3254818
Be careful :int type Occupy 4byte 32 position
Processing data
Binary system :11 0001 1010 1010 0010 0010 (22 position , Insufficient 32 position , Then fill 0 To 32 position )
0000 0000 0011 0001 1010 1010 0010 0010 (32 position )
h>>>16 unsigned right shift 16 position
0000 0000 0000 0000 0000 0000 0011 0001
^ Exclusive or operation : Same as 0, The difference is 1, It can be understood as Add without carry
Data processing finished , Start XOR operation
h = key.hashCode() ^ (h >>> 16)
0000 0000 0011 0001 1010 1010 0010 0010 ( h = key.hashCode())
^ ( Exclusive or )
0000 0000 0000 0000 0000 0000 0011 0001 (h >>> 16)
The result is :
0000 0000 0011 0001 1010 1010 0001 0011
3245803 ( Decimal results )

The calculated results are consistent with the results fed back by the program

Many friends will ask after reading , Why would you hashCode Value shift right 16 Bit and with the original hashCode Value for ^( Bitwise XOR ) operation ?
- Move right 16 Bit is to make high 16 Bits are also involved , Better uniform hashing , Reduce collisions , Further reduction hash The odds of conflict
- The XOR operation is to better preserve the two groups 32 The respective characteristics of a binary number
If you are using &( Bitwise AND ) operation , Then the result will be :
It is obvious that 2 Hexadecimal result direction 0 close , Because the result of bitwise and has 4 Kind of , Only 1&1 The result is 1, The rest of the cases are 0, In this way, it is not only unable to retain the respective characteristics of the original two sets of data , It will also be significantly raised hash The odds of conflict

If you are using |( Press bit or ) operation , Then the result will be :
It can be found that although the result of the same XOR is not very different , But it can also be found that the result is 1 close , And can not well retain their own characteristics
besides , The biggest difference between XOR and or is , XOR can only satisfy one condition , And or can satisfy both conditions at the same time
Exclusive or : Same as 0, The difference is 1 , If the result is 1, What may happen is 00 11 This situation can well retain their own characteristics , Because they are all the same 0 Good 1 Let it be
or : There is one for 1 Then for 1, All two are 0 Then for 0 , If the result is 1, What may happen is 10 11, In these cases, it is difficult for us to judge the characteristics of the two groups of data involved in the operation
Obviously bitwise OR (|) The operation can not well preserve the characteristics of two groups of numbers

The above content is only for personal interpretation , If there is any misunderstanding , Welcome to comment , Thank you
边栏推荐
- TCP connection details
- Single cell paper record (Part14) -- costa: unsupervised revolutionary neural network learning for St analysis
- Current harmonic suppression strategy of grid connected inverter with PIR controller regulator
- pgsql批量插入
- 纵向求最大最小与横向求最大最小greatest(),least(),max(),min()
- reduce_sum()中的reduction_indices
- Unity development - scene asynchronous loading
- Frame profiling
- Conversion between gray code and binary
- Test platform for combinational logic blocks
猜你喜欢

【技术随记】

生信文献学习(part1)--PRECISE: a ... approach to transfer predictors of drug response from pre-clinical ...

401-字符串(344. 反转字符串、541. 反转字符串II、题目:剑指Offer 05.替换空格、151. 颠倒字符串中的单词)

Modeling and Simulation of Radar Seeker Servo System

Current harmonic suppression strategy of grid connected inverter with PIR controller regulator

虚职、架空、拖后腿,大厂开源办公室到底什么样?

舰载机自动着舰控制系统研究

富设备平台突破:基于RK3568的DAYU200进入OpenHarmony 3.1 Release主干

单细胞文献学习(part3)--DSTG: deconvoluting spatial transcriptomics data through graph-based AI

C#中的泛型
随机推荐
Ethernet communication protocol
Le contrôle MFC tabctrl modifie la taille de l'étiquette
878. 第 N 个神奇数字 数学+二分
【Rust笔记】01-基本类型
常用CMOS模拟开关功能和原理
Vulkan pre rotation processing equipment direction
MFC tab control add Icon
不务正业系列7:老照片去除斑点手法
postgresql数据库中根据某个字段判断存在则更新(update)操作,不存在则插入(insert)
Ptrade trading program code - from zero to firm offer 19
Shengxin visualization (Part4) -- correlation diagram
400-哈希表(1. 两数之和、454. 四数相加 II、383. 赎金信)
Combinatorial logic described using SystemVerilog gate model
On the matrix order of MNIST linear model
纵向求最大最小与横向求最大最小greatest(),least(),max(),min()
[technical notes]
reduce_sum()中的reduction_indices
虚职、架空、拖后腿,大厂开源办公室到底什么样?
Shengxin visualization (Part1) -- histogram
Linear regression: least squares, Tellson estimation, RANSAC