@ SuppressWarnings ( "unchecked" ) private void decreaseKey ( Node < K , V > n , K newKey ) { int c ; if ( comparator == null ) { c = ( ( Comparable < ? super K > ) newKey ) . compareTo ( n . key ) ; } else { c = comparator . compare ( newKey , n . key ) ; } if ( c > 0 ) { throw new IllegalArgumentException ( "Keys can only be decreased!" ) ; } n . key = newKey ; if ( c == 0 || root == n ) { return ; } if ( n . o_s == null ) { throw new IllegalArgumentException ( "Invalid handle!" ) ; } // unlink from parent if ( n . y_s != null ) { n . y_s . o_s = n . o_s ; } if ( n . o_s . o_c == n ) { // I am the oldest :( n . o_s . o_c = n . y_s ; } else { // I have an older sibling! n . o_s . y_s = n . y_s ; } n . y_s = null ; n . o_s = null ; // merge with root if ( comparator == null ) { root = link ( root , n ) ; } else { root = linkWithComparator ( root , n ) ; } }
Decrease the key of a node .