protected void flowIntoRootNode ( GrowQueue_I32 regionMemberCount ) { rootID . resize ( regionMemberCount . size ) ; int count = 0 ; for ( int i = 0 ; i < mergeList . size ; i ++ ) { int p = mergeList . data [ i ] ; // see if it is a root note if ( p == i ) { // mark the root nodes new ID rootID . data [ i ] = count ++ ; continue ; } // traverse down until it finds the root note int gp = mergeList . data [ p ] ; while ( gp != p ) { p = gp ; gp = mergeList . data [ p ] ; } // update the count and change this node into the root node regionMemberCount . data [ p ] += regionMemberCount . data [ i ] ; mergeList . data [ i ] = p ; } }
For each region in the merge list which is not a root node find its root node and add to the root node its member count and set the index in mergeList to the root node . If a node is a root node just note what its new ID will be after all the other segments are removed .