Map key to array index to get complexity to O(1) (constant time).
resize when table size >= threshold (= table size * load factor). resize = 2*original table size (is always power of 2) and hashed location is not null
internal structure is array. each element is a linked entry.
modcount to prevent concurrentmodification
LinkedHashMap
get
containsKey
next
o(1)
o(1)
o(1)
- extends from HashMap. HashMap has some methods reserved for subclassses, like init, recordAccess - LinkedHashMap entry extends HashMap entry and adds two more references to entries before it and after it. thus double-linked list - can be used as LRU list because it can be constructed with access order - iteration is faster than hashmap because nodes are linked
IdentityHashMap
get
containsKey
next
comment
o(1)
o(1)
o(h/n)
save key to table[i] and value to table[i+1]. so table size is twice as capacity
- comparing key only by reference id, not equals method - if there is hash conflict, just rehash by forwarding 2 in table index
WeakHashMap
get
containsKey
next
comment
o(1)
o(1)
o(h/n)
hash table underlying. entry in table extends from WeakReference. Entry is constructed with a reference queue which holds invalid references (entries) after GC. WeakHashMap then queries the queue for invalid references and removes them from the map. Be noted the removal goes silently.
EnumMap
get
containsKey
next
comment
o(1)
o(1)
o(1)
use array underlying. the type of key must be enum and specified when construct
TreeMap
get
containsKey
next
comment
o(log(n))
o(log(n))
o(log(n))
red-black tree underlying, some tree fixes after adding or deleting
ConcurrentHashMap
get
containsKey
next
comment
o(1)
o(1)
o(h/n), h is hashtable capacity
consisted of many segments. each segment has its own lock. be careful its size() and containsValue() method since they may lock entire hashmap
HashMap get containsKey next o(1) o(1) o(h/n)Map key to array index to get complexity to O(1) (constant time).resize when table size >= threshold (= table size * load fact...