In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the role of the expansion operation of HashMap". In the daily operation, I believe that many people have doubts about the role of the expansion operation of HashMap. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what is the role of the expansion operation of HashMap?" Next, please follow the editor to study!
Let's first understand the basic data structure of HashMap. In fact, the description of the above figure is not complete, because apart from the fact that TreeNode and TreeNode are located in the red-black tree, TreeNode actually has pre and next pointers, that is, TreeNode and TreeNode have sequence.
The expansion operation of HashMap doubles the capacity of table so that Node can be reassigned to the new table later.
Set the size of table to n, then the size of newTable is 2n.
The Node in table [j] slot must satisfy Node.hash% n = j. Recalculate position index = Node.hash% 2n.
It is simply speculated that Node.hash% 2n = j or nimj.
Prove: let hash = kn + j
Index = hash% 2n = (kn + j)% 2n
When k is even, index = j, then Node should be in the newTable [j] slot.
When k is odd, Node should be in the slot of newTable [index j].
And because of n=0b000000001000000. The m bit is 1, and the rest bits are 0.
Kn must be expressed as n when k is even.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.