/**Function******************************************************************** Synopsis [Merges the children of `group' with the children of its parent.] Description [Merges the children of `group' with the children of its parent. Disposes of the node pointed by group. If group is the root of the group tree, this procedure leaves the tree unchanged. Returns the pointer to the parent of `group' upon successful termination; NULL otherwise.] SideEffects [None] SeeAlso [Mtr_MakeGroup] ******************************************************************************/ MtrNode * Mtr_DissolveGroup( MtrNode * group /* group to be dissolved */) { MtrNode *parent; MtrNode *last; parent = group->parent; if (parent == NULL) return(NULL); if (MTR_TEST(group,MTR_TERMINAL) || group->child == NULL) return(NULL); /* Make all children of group children of its parent, and make ** last point to the last child of group. */ for (last = group->child; last->younger != NULL; last = last->younger) { last->parent = parent; } last->parent = parent; last->younger = group->younger; if (group->younger != NULL) { group->younger->elder = last; } group->child->elder = group->elder; if (group == parent->child) { parent->child = group->child; } else { group->elder->younger = group->child; } Mtr_DeallocNode(group); return(parent); } /* end of Mtr_DissolveGroup */
/**Function******************************************************************** Synopsis [Disposes of tree rooted at node.] Description [] SideEffects [None] SeeAlso [Mtr_InitTree] ******************************************************************************/ void Mtr_FreeTree( MtrNode * node) { if (node == NULL) return; if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child); Mtr_FreeTree(node->younger); Mtr_DeallocNode(node); return; } /* end of Mtr_FreeTree */
/**Function******************************************************************** Synopsis [Makes a copy of tree.] Description [Makes a copy of tree. If parameter expansion is greater than 1, it will expand the tree by that factor. It is an error for expansion to be less than 1. Returns a pointer to the copy if successful; NULL otherwise.] SideEffects [None] SeeAlso [Mtr_InitTree] ******************************************************************************/ MtrNode * Mtr_CopyTree( MtrNode * node, int expansion) { MtrNode *copy; if (node == NULL) return(NULL); if (expansion < 1) return(NULL); copy = Mtr_AllocNode(); if (copy == NULL) return(NULL); copy->parent = copy->elder = copy->child = copy->younger = NULL; if (node->child != NULL) { copy->child = Mtr_CopyTree(node->child, expansion); if (copy->child == NULL) { Mtr_DeallocNode(copy); return(NULL); } } if (node->younger != NULL) { copy->younger = Mtr_CopyTree(node->younger, expansion); if (copy->younger == NULL) { Mtr_FreeTree(copy); return(NULL); } } copy->flags = node->flags; copy->low = node->low * expansion; copy->size = node->size * expansion; copy->index = node->index * expansion; if (copy->younger) copy->younger->elder = copy; if (copy->child) { MtrNode *auxnode = copy->child; while (auxnode != NULL) { auxnode->parent = copy; auxnode = auxnode->younger; } } return(copy); } /* end of Mtr_CopyTree */
/**Function******************************************************************** Synopsis [Merges the children of `group' with the children of its parent.] Description [Merges the children of `group' with the children of its parent. Disposes of the node pointed by group. If group is the root of the group tree, this procedure leaves the tree unchanged. Returns the pointer to the parent of `group' upon successful termination; NULL otherwise.] SideEffects [None] SeeAlso [Mtr_MakeGroup] ******************************************************************************/ MtrNode * Mtr_DissolveGroup( MtrNode * group /* group to be dissolved */) { MtrNode *parent; MtrNode *last; parent = group->parent; if (parent == NULL) return(NULL); #if 1 /* NuSmv change begins */ if (MTR_TEST(group,MTR_TERMINAL) || group->child == NULL) { if (group->younger != NULL) { group->younger->elder = group->elder; } if (group->elder != NULL) { group->elder->younger = group->younger; } if (parent->child == group) { if (group->elder != NULL) { fprintf(stderr, "FAILING GROUP: low=%d, idx=%d, size=%d\n", group->low, group->index, group->size); fprintf(stderr, "Elder that should be null: low=%d, idx=%d, size=%d\n", group->elder->low, group->elder->index, group->elder->size); assert(0); assert(0); } parent->child = group->younger; } Mtr_DeallocNode(group); return parent; } /* NuSmv change ends */ #else if (MTR_TEST(group,MTR_TERMINAL) || group->child == NULL) return NULL; #endif /* Make all children of group children of its parent, and make ** last point to the last child of group. */ for (last = group->child; last->younger != NULL; last = last->younger) { last->parent = parent; } last->parent = parent; last->younger = group->younger; if (group->younger != NULL) { group->younger->elder = last; } group->child->elder = group->elder; if (group == parent->child) { parent->child = group->child; } else { group->elder->younger = group->child; } Mtr_DeallocNode(group); return(parent); } /* end of Mtr_DissolveGroup */