int ANodeSortedIterator::cmpByDynInfo(const void* a, const void* b) { ANode* x = (*(ANode**)a); ANode* y = (*(ANode**)b); // 0. test for equality if (x == y) { return 0; } // INVARIANT: x != y, so never return 0 ADynNode* x_dyn = dynamic_cast<ADynNode*>(x); ADynNode* y_dyn = dynamic_cast<ADynNode*>(y); // 1. distinguish by dynamic info if (x_dyn && y_dyn) { return cmpByDynInfoSpecial(x_dyn, y_dyn); } // 2. distinguish by structure ids uint x_id = x->structureId(); uint y_id = y->structureId(); if (x_id != Prof::Struct::ANode::Id_NULL && y_id != Prof::Struct::ANode::Id_NULL) { int cmp_sid = cmp(x_id, y_id); if (cmp_sid != 0) { return cmp_sid; } } // 3. distinguish by type int cmp_ty = (int)x->type() - (int)y->type(); if (cmp_ty != 0) { return cmp_ty; } #if 1 // 4. distinguish by id int cmp_id = (int)x->id() - (int)y->id(); if (cmp_id != 0) { return cmp_id; } #endif // *. Could compare childCount() and other aspects of children. DIAG_Die("Prof::CCT::ANodeSortedIterator::cmpByDynInfo: cannot compare:" << "\n\tx: " << x->toStringMe(Prof::CCT::Tree::OFlg_Debug) << "\n\ty: " << y->toStringMe(Prof::CCT::Tree::OFlg_Debug)); }
int ANodeSortedIterator::cmpByStructureInfo(const void* a, const void* b) { ANode* x = (*(ANode**)a); ANode* y = (*(ANode**)b); if (x && y) { // 0. test for equality if (x == y) { return 0; } // INVARIANT: x != y, so never return 0 // 1. distinguish by structure ids uint x_id = x->structureId(); uint y_id = y->structureId(); int cmp_sid = cmp(x_id, y_id); if (cmp_sid != 0) { return cmp_sid; } // 2. distinguish by types int cmp_ty = (int)x->type() - (int)y->type(); if (cmp_ty != 0) { return cmp_ty; } // 3. distinguish by dynamic info (unnormalized CCTs) // (for determinism, ensure x and y are both ADynNodes) ADynNode* x_dyn = dynamic_cast<ADynNode*>(x); ADynNode* y_dyn = dynamic_cast<ADynNode*>(y); if (x_dyn && y_dyn) { int cmp_dyn = cmpByDynInfoSpecial(x_dyn, y_dyn); if (cmp_dyn != 0) { return cmp_dyn; } } // 5. distinguish by id int cmp_id = (int)x->id() - (int)y->id(); if (cmp_id != 0) { return cmp_id; } // 4. distinguish by tree context ANode* x_parent = x->parent(); ANode* y_parent = y->parent(); if (x_parent != y_parent) { int cmp_ctxt = cmpByStructureInfo(&x_parent, &y_parent); if (cmp_ctxt != 0) { return cmp_ctxt; } } // *. Could compare childCount() and other aspects of children. DIAG_Die("Prof::CCT::ANodeSortedIterator::cmpByStructureInfo: cannot compare:" << "\n\tx: " << x->toStringMe(Prof::CCT::Tree::OFlg_Debug) << "\n\ty: " << y->toStringMe(Prof::CCT::Tree::OFlg_Debug)); return 0; } else if (x) { return 1; // x > y=NULL (only used for recursive case) } else if (y) { return -1; // x=NULL < y (only used for recursive case) } else { DIAG_Die(DIAG_UnexpectedInput); } }