/* * recursive sub-function of compactToUnicodeHelper() * returns: * >0 number of bytes that are used in unicodeCodeUnits[] that could be saved, * if all sequences from this state are unassigned, returns the * <0 there are assignments in unicodeCodeUnits[] * 0 no use of unicodeCodeUnits[] */ static int32_t findUnassigned(UCMStates *states, uint16_t *unicodeCodeUnits, _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, int32_t state, int32_t offset, uint32_t b) { int32_t i, entry, savings, localSavings, belowSavings; UBool haveAssigned; localSavings=belowSavings=0; haveAssigned=FALSE; for(i=0; i<256; ++i) { entry=states->stateTable[state][i]; if(MBCS_ENTRY_IS_TRANSITION(entry)) { savings=findUnassigned(states, unicodeCodeUnits, toUFallbacks, countToUFallbacks, MBCS_ENTRY_TRANSITION_STATE(entry), offset+MBCS_ENTRY_TRANSITION_OFFSET(entry), (b<<8)|(uint32_t)i); if(savings<0) { haveAssigned=TRUE; } else if(savings>0) { printf(" all-unassigned sequences from prefix 0x%02lx state %ld use %ld bytes\n", (unsigned long)((b<<8)|i), (long)state, (long)savings); belowSavings+=savings; } } else if(!haveAssigned) { switch(MBCS_ENTRY_FINAL_ACTION(entry)) { case MBCS_STATE_VALID_16: entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); if(unicodeCodeUnits[entry]==0xfffe && ucm_findFallback(toUFallbacks, countToUFallbacks, entry)<0) { localSavings+=2; } else { haveAssigned=TRUE; } break; case MBCS_STATE_VALID_16_PAIR: entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); if(unicodeCodeUnits[entry]==0xfffe) { localSavings+=4; } else { haveAssigned=TRUE; } break; default: break; } } } if(haveAssigned) { return -1; } else { return localSavings+belowSavings; } }
/* helper function for finding compaction opportunities */ static void compactToUnicodeHelper(UCMStates *states, uint16_t *unicodeCodeUnits, _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks) { int32_t state, savings; /* for each initial state */ for(state=0; state<states->countStates; ++state) { if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) { savings=findUnassigned(states, unicodeCodeUnits, toUFallbacks, countToUFallbacks, state, 0, 0); if(savings>0) { printf(" all-unassigned sequences from initial state %ld use %ld bytes\n", (long)state, (long)savings); } } } }
//Main solver function bool fillSudoku() { int row, col; //Check whether grid is filled; if not then return first unassigned value if(!findUnassigned(row, col)) { return TRUE; } //Backtracking is used here. int num; for(num=1;num<SIZE+1;num++) { if(checkSafe(row,col,num)) { cell[row][col]=num; if(fillSudoku()) return TRUE; cell[row][col]=0; } } return FALSE; }