boolean reset ( double useChance , int targetCount , boolean isWrite ) { this . isWrite = isWrite ; if ( this . useChance < 1d ) { // we clear our prior roll-modifiers if the use chance was previously less-than zero Arrays . fill ( rollmodifier , 1d ) ; Arrays . fill ( chancemodifier , 1d ) ; } // set the seed for the first clustering component generator . clusteringComponents . get ( 0 ) . setSeed ( idseed ) ; // calculate how many first clustering components we'll generate, and how many total rows this predicts int firstComponentCount = ( int ) generator . clusteringComponents . get ( 0 ) . clusteringDistribution . next ( ) ; int expectedRowCount ; int position = seed . position ( ) ; if ( isWrite ) expectedRowCount = firstComponentCount * generator . clusteringDescendantAverages [ 0 ] ; else if ( position != 0 ) expectedRowCount = setLastRow ( position - 1 ) ; else expectedRowCount = setNoLastRow ( firstComponentCount ) ; if ( Double . isNaN ( useChance ) ) useChance = Math . max ( 0d , Math . min ( 1d , targetCount / ( double ) expectedRowCount ) ) ; this . useChance = useChance ; while ( true ) { // we loop in case we have picked an entirely non-existent range, in which case // we will reset the seed's position, then try again (until we exhaust it or find // some real range) for ( Queue < ? > q : clusteringComponents ) q . clear ( ) ; clusteringSeeds [ 0 ] = idseed ; fill ( clusteringComponents [ 0 ] , firstComponentCount , generator . clusteringComponents . get ( 0 ) ) ; if ( ! isWrite ) { if ( seek ( 0 ) != State . SUCCESS ) throw new IllegalStateException ( ) ; return true ; } int count = Math . max ( 1 , expectedRowCount / seed . visits ) ; position = seed . moveForwards ( count ) ; isFirstWrite = position == 0 ; setLastRow ( position + count - 1 ) ; // seek to our start position switch ( seek ( position ) ) { case END_OF_PARTITION : return false ; case SUCCESS : return true ; } } }
initialise the iterator state