public TrieNode split ( ) { if ( getData ( ) . firstChildIndex < 0 ) { TreeMap < Character , SerialArrayList < CursorData > > sortedChildren = new TreeMap <> ( getCursors ( ) . parallel ( ) . collect ( Collectors . groupingBy ( y -> y . next ( ) . getToken ( ) , Collectors . reducing ( new SerialArrayList <> ( CursorType . INSTANCE , 0 ) , cursor -> new SerialArrayList <> ( CursorType . INSTANCE , cursor . data ) , ( left , right ) -> left . add ( right ) ) ) ) ) ; long cursorWriteIndex = getData ( ) . firstCursorIndex ; //System.err.println(String.format("Splitting %s into children: %s", getDebugString(), sortedChildren.keySet())); ArrayList < NodeData > childNodes = new ArrayList <> ( sortedChildren . size ( ) ) ; for ( Map . Entry < Character , SerialArrayList < CursorData > > e : sortedChildren . entrySet ( ) ) { int length = e . getValue ( ) . length ( ) ; ( ( CharTrieIndex ) this . trie ) . cursors . putAll ( e . getValue ( ) , ( int ) cursorWriteIndex ) ; childNodes . add ( new NodeData ( e . getKey ( ) , ( short ) - 1 , - 1 , length , cursorWriteIndex ) ) ; cursorWriteIndex += length ; } int firstChildIndex = this . trie . nodes . addAll ( childNodes ) ; short size = ( short ) childNodes . size ( ) ; trie . ensureParentIndexCapacity ( firstChildIndex , size , index ) ; this . trie . nodes . update ( index , data -> { return data . setFirstChildIndex ( firstChildIndex ) . setNumberOfChildren ( size ) ; } ) ; return new IndexNode ( this . trie , getDepth ( ) , index , getParent ( ) ) ; } else { return this ; } }
Split trie node .