当前位置:网站首页>The division principle summary within the collection

The division principle summary within the collection

2022-08-09 06:32:00 The strongest disciple in history

ArrayList
1. Constructor
new Arraylist(size)
if size ==0 {} 
else if size>0 new Object[size];

2. default CAPACITY 10

Expansion:
1. Construct method to expand
2. Add grow method 1.5 times.

HashSet
1. Constructor
Math.max((int) (c.size()/.75f) + 1, 16) 16 or size/0.75 +1 This is for discrete distribution.

2. The bottom layer is the hashmap structure map.put(e, PRESENT);

HashMap
1. The auto-increment factor is 0.75
2. The default capacity is 16 When the number of elements in the HashMap exceeds the capacity * loading factor, the HashMap will expand the capacity


Hash methods to avoid conflicts:
1. Open address method: The open address method is to find the next empty hash address once a conflict occurs, as long as the hash table is large enough, the empty hashThe column address is always found and the record is stored.
2. Re-hash method: If the address conflicts, perform the address and re-hash.
3. Chain address method: The node of the array extends the external node into a linked list structure.


rehash()
0.75*size()
When the number of entries in the hash table exceeds the product of the load factor and the current capacity, and the location to be stored already has elements (hashcollision), two conditions must be met to expand the capacity.
2x the growth

ConcurrentHashMap
  
put 方法加锁锁的对象是hash 数组的node。
The get method is not locked, volatile.

原网站

版权声明
本文为[The strongest disciple in history]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090629204929.html