ICU-2123 Replace awkward RBBI builder data structure. Linked list of
uset nodes replaced by a vector; overloaded use of right child field of node eliminated. X-SVN-Rev: 9812
This commit is contained in:
parent
956c28b0ac
commit
d2e6ab9355
@ -107,11 +107,6 @@ RBBINode::~RBBINode() {
|
||||
// Storage ownership of children handled elsewhere. Don't delete here.
|
||||
break;
|
||||
|
||||
case uset:
|
||||
delete fLeftChild;
|
||||
// For usets, don't delete the right child; it's used to form a linked list of usets.
|
||||
break;
|
||||
|
||||
default:
|
||||
delete fLeftChild;
|
||||
fLeftChild = NULL;
|
||||
@ -258,7 +253,7 @@ void RBBINode::findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &s
|
||||
if (fLeftChild != NULL) {
|
||||
fLeftChild->findNodes(dest, kind, status);
|
||||
}
|
||||
if (fRightChild !=NULL && fType != RBBINode::uset) {
|
||||
if (fRightChild != NULL) {
|
||||
fRightChild->findNodes(dest, kind, status);
|
||||
}
|
||||
}
|
||||
@ -331,9 +326,7 @@ void RBBINode::printTree(UBool printHeading, UBool doVars) {
|
||||
fLeftChild->printTree(FALSE);
|
||||
}
|
||||
|
||||
// Note: The right child field of uset nodes is borrowed to link them into a list
|
||||
// They are actually a leaf node as far as the tree is concerned.
|
||||
if (fRightChild != NULL && this->fType != RBBINode::uset) {
|
||||
if (fRightChild != NULL) {
|
||||
fRightChild->printTree(FALSE);
|
||||
}
|
||||
}
|
||||
|
@ -53,17 +53,17 @@ RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
|
||||
fDebugEnv = getenv("U_RBBIDEBUG");
|
||||
#endif
|
||||
|
||||
fScanner = new RBBIRuleScanner(this);
|
||||
fSetBuilder = new RBBISetBuilder(this);
|
||||
if(fSetBuilder == 0 || fScanner == 0) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
||||
fSetsListHead = NULL;
|
||||
fForwardTree = NULL;
|
||||
fReverseTree = NULL;
|
||||
fForwardTables = NULL;
|
||||
fReverseTables = NULL;
|
||||
fUSetNodes = new UVector(status);
|
||||
fScanner = new RBBIRuleScanner(this);
|
||||
fSetBuilder = new RBBISetBuilder(this);
|
||||
if(fSetBuilder == 0 || fScanner == 0 || fUSetNodes == 0) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -75,17 +75,16 @@ RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
|
||||
//----------------------------------------------------------------------------------------
|
||||
RBBIRuleBuilder::~RBBIRuleBuilder() {
|
||||
|
||||
// Delete the linked lest of USet nodes and the corresponding UnicodeSets.
|
||||
// (Deleting a node deletes its children, so deleting the head node of
|
||||
// this list will take out the whole list.)
|
||||
RBBINode *n, *nextN;
|
||||
for (n=fSetsListHead; n!=NULL; n=nextN) {
|
||||
nextN = n->fRightChild;
|
||||
int i;
|
||||
for (i=0; ; i++) {
|
||||
RBBINode *n = (RBBINode *)fUSetNodes->elementAt(i);
|
||||
if (n==NULL) {
|
||||
break;
|
||||
}
|
||||
delete n;
|
||||
}
|
||||
fSetsListHead = NULL;
|
||||
|
||||
|
||||
delete fUSetNodes;
|
||||
delete fSetBuilder;
|
||||
delete fForwardTables;
|
||||
delete fReverseTables;
|
||||
|
@ -171,8 +171,7 @@ public:
|
||||
RBBINode *fReverseTree; // then manipulated by subsequent steps.
|
||||
|
||||
RBBISetBuilder *fSetBuilder; // Set and Character Category builder.
|
||||
RBBINode *fSetsListHead; // Head of the linked list of UnicodeSets
|
||||
// (uset nodes.)
|
||||
UVector *fUSetNodes; // Vector of all uset nodes.
|
||||
|
||||
RBBITableBuilder *fForwardTables; // State transition tables
|
||||
RBBITableBuilder *fReverseTables;
|
||||
|
@ -651,10 +651,10 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
|
||||
|
||||
|
||||
//
|
||||
// Link the new uset node into the list of all uset nodes.
|
||||
// Add the new uset node to the list of all uset nodes.
|
||||
//
|
||||
usetNode->fRightChild = fRB->fSetsListHead;
|
||||
fRB->fSetsListHead = usetNode;
|
||||
fRB->fUSetNodes->addElement(usetNode, *fRB->fStatus);
|
||||
|
||||
|
||||
//
|
||||
// Add the new set to the set hash table.
|
||||
|
@ -141,7 +141,13 @@ void RBBISetBuilder::build() {
|
||||
//
|
||||
// Find the set of non-overlapping ranges of characters
|
||||
//
|
||||
for (usetNode=fRB->fSetsListHead; usetNode!=NULL; usetNode=usetNode->fRightChild) {
|
||||
int ni;
|
||||
for (ni=0; ; ni++) {
|
||||
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
|
||||
if (usetNode==NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
UnicodeSet *inputSet = usetNode->fInputSet;
|
||||
int32_t inputSetRangeCount = inputSet->getRangeCount();
|
||||
int inputSetRangeIndex = 0;
|
||||
@ -413,18 +419,20 @@ void RBBISetBuilder::printRangeGroups() {
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
void RBBISetBuilder::printSets() {
|
||||
RBBINode *usetNode;
|
||||
int i;
|
||||
UnicodeSet inputSet;
|
||||
|
||||
RBBIDebugPrintf("\n\nUnicode Sets List\n------------------\n");
|
||||
i = 0;
|
||||
for (usetNode=fRB->fSetsListHead; usetNode!=NULL; usetNode=usetNode->fRightChild) {
|
||||
RBBINode *setRef;
|
||||
RBBINode *varRef;
|
||||
UnicodeString setName;
|
||||
for (i=0; ; i++) {
|
||||
RBBINode *usetNode;
|
||||
RBBINode *setRef;
|
||||
RBBINode *varRef;
|
||||
UnicodeString setName;
|
||||
|
||||
usetNode = (RBBINode *)fRB->fUSetNodes->elementAt(i);
|
||||
if (usetNode == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
RBBIDebugPrintf("%3d ", i);
|
||||
setName = "anonymous";
|
||||
setRef = usetNode->fParent;
|
||||
|
Loading…
Reference in New Issue
Block a user