Hash tables and hash algorithm conflict


Hash table (K, v) array, according to the corresponding hash algorithm key subscript, superscript return value is an array v stored
hash algorithms: f (K) -> the array v is the need to be stored int standard
hash algorithm: 16%
find, add elements: O (1)

hash collision solution:
are equal two different objects hash value calculated hash algorithm
EG:. 1. 17% 16% 16 ==
a, open-addressable
find the next array index is null, and after the conflict storage elements

B, contained in hashing
using a different hash algorithm once again recalculated

C, chain address method (method zipper): HashMap use this method to resolve hash collisions
all the elements of the conflict in accordance with the list stored in
O (n-+. 1)
the HashMap permit key, value is null
the Hashtable, and the key value can not be empty pointer exception is
the TreeMap, since it is necessary to achieve the sort, it can not be empty key, value can be null pointer exception


with thread safety data:
HashMap, TreeMap uses asynchronous processing, thread-safe, high performance
Hashtable using synchronized synchronization method, thread-safe, low performance (lock the entire hash table, read exclusive)

internal belong
Load factor loadFactor, default 0.75f
actual capacity int threshold
tree threshold int TREEIFY - THRESHOLD = 8
release threshold tree un = 6
HashMap using lazy loading strategy, for the first time put the hash table is initialized when


7.HashMap source parsing (load factor, tree strategy, internal hash achieve, resize strategy ..)
8.ConcurrentHashMap is how to efficiently implement a thread-safe?
The difference 9.ConcurrentHashMap jdk1.7 and jdk1.8

6.HashMap, TreeMap, HashTable relationship with the difference between 
a, three classes are used in the Map interface, word, Hashtable hash table based on the realization, TreeMap based on a red-black tree implementation, HashMap hash table based black tree +

Guess you like

Origin www.cnblogs.com/hetaoyuan/p/11241820.html