private void searchPrefixes ( int depth , int [ ] choices , List < int [ ] > prefixes ) { if ( depth == 0 ) { prefixes . add ( choices . clone ( ) ) ; } else { ColumnHeader < ColumnName > col = findBestColumn ( ) ; if ( col . size > 0 ) { coverColumn ( col ) ; Node < ColumnName > row = col . down ; int rowId = 0 ; while ( row != col ) { Node < ColumnName > node = row . right ; while ( node != row ) { coverColumn ( node . head ) ; node = node . right ; } choices [ choices . length - depth ] = rowId ; searchPrefixes ( depth - 1 , choices , prefixes ) ; node = row . left ; while ( node != row ) { uncoverColumn ( node . head ) ; node = node . left ; } row = row . down ; rowId += 1 ; } uncoverColumn ( col ) ; } } }
Generate a list of prefixes down to a given depth . Assumes that the problem is always deeper than depth .