public final V put ( K key , V value ) { BinTreeNode < K , V > prev = null ; BinTreeNode < K , V > node = root ; int key_hash_code = key . hashCode ( ) ; while ( node != null ) { prev = node ; if ( key_hash_code < node . keyHashCode ) { node = node . left ; } else { if ( ( key_hash_code > node . keyHashCode ) || ! node . key . equals ( key ) ) { node = node . right ; } else { cachedHashCode -= node . hashCode ( ) ; V temp = node . value ; node . value = value ; cachedHashCode += node . hashCode ( ) ; return temp ; } } } size ++ ; BinTreeNode < K , V > new_node = new BinTreeNode < K , V > ( key , value ) ; cachedHashCode += new_node . hashCode ( ) ; // invalidate the cached hash code if ( prev == null ) { root = new_node ; return null ; } if ( key_hash_code < prev . keyHashCode ) { prev . left = new_node ; } else { prev . right = new_node ; } return null ; }
Associates the specified value with the specified key in this map .