private void compact ( final CharSequence key ) { final int keyLength = key . length ( ) ; TrieNode < V > currentNode = getRoot ( ) ; TrieNode < V > lastInUseNode = currentNode ; int lastInUseIndex = 0 ; for ( int i = 0 ; i < keyLength && currentNode != null ; i ++ ) { if ( currentNode . inUse ) { lastInUseNode = currentNode ; lastInUseIndex = i ; } currentNode = currentNode . children . get ( key . charAt ( i ) ) ; } currentNode = lastInUseNode ; for ( int i = lastInUseIndex ; i < keyLength ; i ++ ) { currentNode = currentNode . children . remove ( key . charAt ( i ) ) . unset ( ) ; } }
Compact the trie by removing unused nodes on the path that is specified by the given key .