How HashTable(HashMap) works and preformance

Hashing :How Hash Map Works In Java Or How Get() Method Works Internally
How hashmap works in java

http://kakajw.iteye.com/blog/935226
http://www.importnew.com/7099.html
http://xiaolu123456.iteye.com/blog/1485349


An instance of HashMap has two parameters that affect its performance: initial capacity and load factor.

DEFAULT_INITIAL_CAPACITY常量:
The default initial capacity - MUST be a power of two (2 ^ n: 2的n次方).

static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

设定 initialCapacity

public HashMap(int initialCapacity) {
    this(initialCapacity, DEFAULT_LOAD_FACTOR);
}

The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created.

DEFAULT_LOAD_FACTOR常量:
The load factor used when none specified in constructor.

static final float DEFAULT_LOAD_FACTOR = 0.75f;

设定 loadFactor

public HashMap(int initialCapacity, float loadFactor) { ... }

The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased.

When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.

resize方法:

resize() { ... }

Initializes or doubles table size. If null, allocates in accord with initial capacity target held in field threshold. Otherwise, because we are using power-of-two expansion, the elements from each bin must either stay at same index, or move with a power of two offset in the new table.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值