当前位置:网站首页>e. Hash & oldcap = = 0 detailed interpretation
e. Hash & oldcap = = 0 detailed interpretation
2022-06-22 06:10:00 【Xiaoshuang is handsome enough to drag the Internet speed】
e.hash & oldCap == 0 Detailed interpretation
Press (e.hash & oldCap) Is it equal to 0 There are two situations ( In the process of derivation, always pay attention to : The array length before and after the expansion is 2 Of n The next power , This is HashMap Specified by the underlying source code ):
situation 1:【 Derivation process 1】 When e.hash&oldCap be equal to 0 when ,e The index position in the old and new arrays remains the same :(2oldCap-1)& e.hash = (oldCap -1) & e.hash
situation 2:【 Derivation process 2】 When e.hash&oldCap It's not equal to 0 The elements of ,e The index position in the new array is its index position in the old array plus the length offset of the old array : (2oldCap-1)& e.hash = (oldCap -1) &e.hash+oldCap
oldCap yes table The capacity of , Follow the strategy of the source code , It must be 2^n Power , It means that 2 There must be only one base 1, The rest are 0; If you want to guarantee e.hash&oldCap ==0, You just need to e.hash In the corresponding oldCap The binary bits are in 1 The one who is 0, You can guarantee the final biting and operation (&) The result is 0; If e.hash&oldCap !=0 , You just need to e.hash In the corresponding oldCap The binary bits are in 1 The one who is 1, You can guarantee the final bitwise and operation (&) It's not equal to 0
hypothesis oldCap = 16 = 2^4 = 10000( Binary system )
Derivation process 1:
Want to satisfy e.hash&oldCap ==0, hypothesis e.hash = 01111 ( Be careful , there e.hash After the initial hash(key) Calculated ), Pay attention to this 01111 in 0 The position of is corresponding to oldCap The only one in the binary system 1 The location of )
10000 & 01111
be oldCap & e.hash = 10000 & 01111 = 00000( Binary system ) = 0( Decimal system )
When adding elements , This calculation method is used to find the corresponding subscript in the array for the element to be added

Now we have doubled the capacity of the array , The formula must be modified
(2oldCap-1)& e.hash = (2^5 - 1)& 0 1111 = 01 1111 & 0 1111 = 00 0000( Binary system )= 0( Decimal system )
(oldCap -1)& e.hash = (2^4 - 1)& 0 1111 = 0 1111 & 0 1111 = 0 0000( Binary system ) = 0 ( Decimal system )
thus it can be seen , If meet e.hash&oldCap ==0 , The subscript position of the element in the old array is the same as that of the element in the new array
(e.hash & oldCap) == 0
if (loTail != null) {
loTail.next = null;
// The subscript position of the element in the old array is the same as that of the element in the new array
newTab[j] = loHead;
}
Derivation process 2:
Want to satisfy e.hash&oldCap !=0, hypothesis e.hash = 11111( Be careful , there e.hash After the initial hash(key) Calculated ), Pay attention to this 11111 First of all 1 The position of is corresponding to oldCap The only one in the binary system 1 The location of )
10000 & 11111
be oldCap & e.hash = 1 0000 & 1 1111 = 1 0000 ( Binary system ) = 16( Decimal system )
When adding elements , Through this i = (n - 1) & hash Calculation method to find the corresponding subscript in the array for the element to be added
(2oldCap-1)& e.hash = (2^5 - 1)& 1 1111 = 01 1111 & 1 1111 = 0001 1111( Binary system )= 31( Decimal system )
(oldCap -1)& e.hash = (2^4 - 1)& 1 1111 = 0 1111 & 1 1111 = 0000 1111( Binary system ) = 15 ( Decimal system )
You can find (oldCap -1)& e.hash + oldCap = 15 + 16 = 31 = (2oldCap-1)& e.hash
thus it can be seen , If meet e.hash&oldCap != 0 , The subscript position of the element in the old array + Old array capacity = The position of the subscript of the element in the new array
e.hash & oldCap) == 0
if (hiTail != null) {
hiTail.next = null;
newTab[j + oldCap] = hiHead;
}
The above is only for personal interpretation , If there is any misunderstanding , Please comment in the comments section , thank you
边栏推荐
- 单细胞文献学习(part3)--DSTG: deconvoluting spatial transcriptomics data through graph-based AI
- R语言观察日志(part24)--writexl包
- 【Rust笔记】03-引用
- W800芯片平台进入OpenHarmony主干
- TiDB 社区线下交流会,天津 & 石家庄的小伙伴看过来~
- Research on automatic landing control system of carrier aircraft
- Shengxin visualization (Part4) -- correlation diagram
- idea本地运行scope
- 活动预告|EdgeX 开发者峰会@南京站 来啦!
- 汇顶科技GR551x系列开发板已支持OpenHarmony
猜你喜欢

Adaboost

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

【自己动手写CPU】异常相关指令的实现

MFC tab control add Icon

Use of idea plug-in EASYCODE

MFC TabCtrl 控件修改標簽尺寸

Unity app improves device availability

Single cell thesis record (part13) -- spagcn: integrating gene expression, spatial location and history to

Modeling and Simulation of Radar Seeker Servo System

单细胞文献学习(part2)--stPlus: a reference-based method for the accurate enhancement of ST
随机推荐
Array and foreach traversal in C #
Ethernet communication protocol
单细胞文献学习(part2)--stPlus: a reference-based method for the accurate enhancement of ST
汇顶科技GR551x系列开发板已支持OpenHarmony
drop、truncate和delete的区别
论文实验记录(part1)--Detection ofnatural clusters via S-DBSCAN a Self-tuning version of DBSCAN
常用CMOS模拟开关功能和原理
Surfer格网文件裁剪
reduce_ Reduction in sum()_ indices
D3D10 screenshot function saves texture to local
MFC tabctrl control to modify label size
400-哈希表(1. 两数之和、454. 四数相加 II、383. 赎金信)
Single cell literature learning (Part2) -- stplus: a reference based method for the exact enhancement of St
Empirical mode decomposition (EMD) and Hilbert Huang transform (HHT)
Flink核心功能和原理
On the definition of jinja2 macro
Use of idea plug-in EASYCODE
Single cell thesis records (part9) -- spatial charting of single cell transcriptomes in lectures
Single cell paper record (Part11) -- clustermap for multi-scale clustering analysis of spatial gene expression
400 hash table (1. sum of two numbers, 454. sum of four numbers II, 383. ransom letter)