@ SuppressWarnings ( "unchecked" ) private void delete ( SoftHandle < K , V > n ) { if ( n . tree == null ) { throw new IllegalArgumentException ( "Invalid handle!" ) ; } /* * Delete from belonging list. Care must be taken as the tree reference * is valid only if the node is the first in the list. */ TreeNode < K , V > tree = n . tree ; if ( tree . cHead != n ) { /* * Not first in list. Each case, remove and leave as ghost element. */ if ( n . next != null ) { n . next . prev = n . prev ; } n . prev . next = n . next ; } else { /* * First in list */ SoftHandle < K , V > nNext = n . next ; tree . cHead = nNext ; if ( nNext != null ) { /* * More elements exists, remove and leave as ghost element. * Update new first element to point to correct tree. */ nNext . prev = null ; nNext . tree = tree ; } else { /* * No more elements, sift. */ sift ( tree ) ; /* * If still no elements, remove tree. */ if ( tree . cHead == null ) { if ( tree . parent instanceof TreeNode ) { TreeNode < K , V > p = ( TreeNode < K , V > ) tree . parent ; if ( p . left == tree ) { p . left = null ; } else { p . right = null ; } } else { delete ( ( RootListNode < K , V > ) tree . parent ) ; } } } } n . tree = null ; n . prev = null ; n . next = null ; size -- ; }
Delete an element .