在HashMap中或哈希表换汤不换药过程 [英] Rehashing process in hashmap or hashtable

查看:175
本文介绍了在HashMap中或哈希表换汤不换药过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个HashMap或哈希表中的重散列的过程完成后的大小超过maxthreshold值?

How is the rehashing process done in a hashmap or hashtable when the size exceeds the maxthreshold value?

只是复制到桶的新数组所有对?

Are all pairs just copied to a new array of buckets?

编辑:

什么碰巧在同一桶重散列后的元素(在链表)?我的意思是他们将继续留在同一个桶中后,老调重弹?

What happen to the elements in the same bucket (in linked list) after rehashing? I mean will they remain in same bucket after rehashing?

推荐答案

在问题上的最大阈值被称为负载系数。

The maximum threshold in the question is called the load factor.

最好是具有约0.75的负载因子。负载因数定义为(M / N),其中n是哈希表的总大小,m是pferred的$ P $它可以在所需的基本数据结构的大小的增量之前插入的条目数。

It is advisable to have a load factor of around 0.75. Load factor is defined as (m/n) where n is the total size of the hash table and m is the preferred number of entries which can be inserted before a increment in size of the underlying data structure is required.

老调重弹可以在两种情况下进行:

Rehashing can be done in two cases:

  1. 在present M'超越客座率/ N比增加

  1. When the present m'/n ratio increases beyond the load factor

M'/ N比率下降到非常低的值表示0.1

M'/n ratio falls to a very low value say 0.1

在这两种情况下m'为条目的当前数量。此外,这两种情况下需要的present条目的移位成一个更大或更小的哈希表。

In both the cases m' is the current number of entries. Also, both the cases demand the shifting of the present entries into a bigger or a smaller hash table.

在问题的上下文重散列是施加一个散列函数来的条目将其移动到另一个哈希表的过程。也可以使用散列函数将其之前使用或完全使用一个新的功能。

In the question's context rehashing is the process of applying a hash function to the entries to move them to another hash table. It is possible to use the hash function which was used earlier or use a new function altogether.

请注意:当碰撞发生时老调重弹也做。 (这是处理过碰撞的方式。)

Please note: Rehashing is also done when a collision occurs. (It's a way of handling collisions too.)

要添加更多的背景和详细的讨论,请访问我的博客散列基础

To add some more context and a detailed discussion please visit my blog Hashing Basics

这篇关于在HashMap中或哈希表换汤不换药过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆