public TrieNode godparent ( ) { if ( 0 == getDepth ( ) ) return null ; TrieNode root = trie . root ( ) ; if ( 1 == getDepth ( ) ) return root ; if ( null != trie . godparentIndex && trie . godparentIndex . length > index ) { int godparentIndex = trie . godparentIndex [ this . index ] ; if ( godparentIndex >= 0 ) { return newNode ( godparentIndex ) ; } } TrieNode parent = this . getParent ( ) ; TrieNode godparent ; if ( null == parent ) { godparent = root ; } else { TrieNode greatgodparent = parent . godparent ( ) ; if ( null == greatgodparent ) { godparent = root ; } else { godparent = greatgodparent . getChild ( getChar ( ) ) . map ( x -> ( TrieNode ) x ) . orElseGet ( ( ) -> root ) ; } //assert(getString().isEmpty() || getString().substring(1).equals(godparent.getString())); } if ( null != godparent && null != trie . godparentIndex && trie . godparentIndex . length > index ) { trie . godparentIndex [ this . index ] = godparent . index ; } return godparent ; }
Godparent trie node .