//
// findDuplCharClassFrom()
//
-bool RBBITableBuilder::findDuplCharClassFrom(int32_t &baseCategory, int32_t &duplCategory) {
+bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) {
int32_t numStates = fDStates->size();
int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
uint16_t table_base;
uint16_t table_dupl;
- for (; baseCategory < numCols-1; ++baseCategory) {
- for (duplCategory=baseCategory+1; duplCategory < numCols; ++duplCategory) {
+ for (; categories->first < numCols-1; categories->first++) {
+ for (categories->second=categories->first+1; categories->second < numCols; categories->second++) {
for (int32_t state=0; state<numStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
- table_base = (uint16_t)sd->fDtran->elementAti(baseCategory);
- table_dupl = (uint16_t)sd->fDtran->elementAti(duplCategory);
+ table_base = (uint16_t)sd->fDtran->elementAti(categories->first);
+ table_dupl = (uint16_t)sd->fDtran->elementAti(categories->second);
if (table_base != table_dupl) {
break;
}
/*
* findDuplicateState
*/
-bool RBBITableBuilder::findDuplicateState(int32_t &firstState, int32_t &duplState) {
+bool RBBITableBuilder::findDuplicateState(IntPair *states) {
int32_t numStates = fDStates->size();
int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
- for (; firstState<numStates-1; ++firstState) {
- RBBIStateDescriptor *firstSD = (RBBIStateDescriptor *)fDStates->elementAt(firstState);
- for (duplState=firstState+1; duplState<numStates; ++duplState) {
- RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(duplState);
+ for (; states->first<numStates-1; states->first++) {
+ RBBIStateDescriptor *firstSD = (RBBIStateDescriptor *)fDStates->elementAt(states->first);
+ for (states->second=states->first+1; states->second<numStates; states->second++) {
+ RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(states->second);
if (firstSD->fAccepting != duplSD->fAccepting ||
firstSD->fLookAhead != duplSD->fLookAhead ||
firstSD->fTagsIdx != duplSD->fTagsIdx) {
int32_t firstVal = firstSD->fDtran->elementAti(col);
int32_t duplVal = duplSD->fDtran->elementAti(col);
if (!((firstVal == duplVal) ||
- ((firstVal == firstState || firstVal == duplState) &&
- (duplVal == firstState || duplVal == duplState)))) {
+ ((firstVal == states->first || firstVal == states->second) &&
+ (duplVal == states->first || duplVal == states->second)))) {
rowsMatch = false;
break;
}
}
-bool RBBITableBuilder::findDuplicateSafeState(int32_t *firstState, int32_t *duplState) {
+bool RBBITableBuilder::findDuplicateSafeState(IntPair *states) {
int32_t numStates = fSafeTable->size();
- for (; *firstState<numStates-1; ++(*firstState)) {
- UnicodeString *firstRow = static_cast<UnicodeString *>(fSafeTable->elementAt(*firstState));
- for (*duplState=*firstState+1; *duplState<numStates; ++(*duplState)) {
- UnicodeString *duplRow = static_cast<UnicodeString *>(fSafeTable->elementAt(*duplState));
+ for (; states->first<numStates-1; states->first++) {
+ UnicodeString *firstRow = static_cast<UnicodeString *>(fSafeTable->elementAt(states->first));
+ for (states->second=states->first+1; states->second<numStates; states->second++) {
+ UnicodeString *duplRow = static_cast<UnicodeString *>(fSafeTable->elementAt(states->second));
bool rowsMatch = true;
int32_t numCols = firstRow->length();
for (int32_t col=0; col < numCols; ++col) {
int32_t firstVal = firstRow->charAt(col);
int32_t duplVal = duplRow->charAt(col);
if (!((firstVal == duplVal) ||
- ((firstVal == *firstState || firstVal == *duplState) &&
- (duplVal == *firstState || duplVal == *duplState)))) {
+ ((firstVal == states->first || firstVal == states->second) &&
+ (duplVal == states->first || duplVal == states->second)))) {
rowsMatch = false;
break;
}
* RemoveDuplicateStates
*/
void RBBITableBuilder::removeDuplicateStates() {
- int32_t firstState = 3;
- int32_t duplicateState = 0;
- while (findDuplicateState(firstState, duplicateState)) {
- // printf("Removing duplicate states (%d, %d)\n", firstState, duplicateState);
- removeState(firstState, duplicateState);
+ IntPair dupls = {3, 0};
+ while (findDuplicateState(&dupls)) {
+ // printf("Removing duplicate states (%d, %d)\n", dupls.first, dupls.second);
+ removeState(dupls.first, dupls.second);
}
}
}
// Remove duplicate or redundant rows from the table.
- int32_t firstState = 1;
- int32_t duplicateState = 0; // initial value is not used; set by findDuplicateSafeState().
- while (findDuplicateSafeState(&firstState, &duplicateState)) {
- // printf("Removing duplicate safe states (%d, %d)\n", firstState, duplicateState);
- removeSafeState(firstState, duplicateState);
+ IntPair states = {1, 0};
+ while (findDuplicateSafeState(&states)) {
+ // printf("Removing duplicate safe states (%d, %d)\n", states.first, states.second);
+ removeSafeState(states.first, states.second);
}
}
#include "unicode/utypes.h"
#include "unicode/uobject.h"
#include "unicode/rbbi.h"
+#include "rbbirb.h"
#include "rbbinode.h"
*/
void exportTable(void *where);
- /** Find duplicate (redundant) character classes, beginning after the specifed
+ /**
+ * Find duplicate (redundant) character classes, beginning at the specified
* pair, within this state table. This is an iterator-like function, used to
- * identify char classes (state table columns) that can be eliminated.
+ * identify character classes (state table columns) that can be eliminated.
+ * @param categories in/out parameter, specifies where to start looking for duplicates,
+ * and returns the first pair of duplicates found, if any.
+ * @return true if duplicate char classes were found, false otherwise.
*/
- bool findDuplCharClassFrom(int &baseClass, int &duplClass);
+ bool findDuplCharClassFrom(IntPair *statePair);
/** Remove a column from the state table. Used when two character categories
* have been found equivalent, and merged together, to eliminate the uneeded table column.
void addRuleRootNodes(UVector *dest, RBBINode *node);
- /** Find the next duplicate state. An iterator function.
- * @param firstState (in/out) begin looking at this state, return the first of the
- * pair of duplicates.
- * @param duplicateState returns the duplicate state of fistState
- * @return true if a duplicate pair of states was found.
+ /**
+ * Find duplicate (redundant) states, beginning at the specified pair,
+ * within this state table. This is an iterator-like function, used to
+ * identify states (state table rows) that can be eliminated.
+ * @param states in/out parameter, specifies where to start looking for duplicates,
+ * and returns the first pair of duplicates found, if any.
+ * @return true if duplicate states were found, false otherwise.
*/
- bool findDuplicateState(int32_t &firstState, int32_t &duplicateState);
+ bool findDuplicateState(IntPair *states);
/** Remove a duplicate state/
* @param keepState First of the duplicate pair. Keep it.
void removeState(int32_t keepState, int32_t duplState);
/** Find the next duplicate state in the safe reverse table. An iterator function.
- * @param firstState ptr to state variable. Begin looking at this state, set to the first of the
- * pair of duplicates on return.
- * @param duplicateState ptr to where to return the duplicate state of fistState. Output only.
- * @return true if a duplicate pair of states was found.
+ * @param states in/out parameter, specifies where to start looking for duplicates,
+ * and returns the first pair of duplicates found, if any.
+ * @return true if a duplicate pair of states was found.
*/
- bool findDuplicateSafeState(int32_t *firstState, int32_t *duplicateState);
+ bool findDuplicateSafeState(IntPair *states);
/** Remove a duplicate state from the safe table.
* @param keepState First of the duplicate pair. Keep it.