94 #ifndef DD_UNSORTED_FREE_LIST
95 #ifdef DD_RED_BLACK_FREE_LIST
97 #define DD_STACK_SIZE 128
100 #define DD_PAGE_SIZE 8192
101 #define DD_PAGE_MASK ~(DD_PAGE_SIZE - 1)
124 static char rcsid[]
DD_UNUSED =
"$Id: cuddTable.c,v 1.122 2009/02/19 16:24:28 fabio Exp $";
132 #ifndef DD_UNSORTED_FREE_LIST
133 #ifdef DD_RED_BLACK_FREE_LIST
135 #define DD_INSERT_COMPARE(x,y) \
136 (((ptruint) (x) & DD_PAGE_MASK) - ((ptruint) (y) & DD_PAGE_MASK))
137 #define DD_COLOR(p) ((p)->index)
138 #define DD_IS_BLACK(p) ((p)->index == DD_BLACK)
139 #define DD_IS_RED(p) ((p)->index == DD_RED)
140 #define DD_LEFT(p) cuddT(p)
141 #define DD_RIGHT(p) cuddE(p)
142 #define DD_NEXT(p) ((p)->next)
157 #ifdef DD_RED_BLACK_FREE_LIST
160 static void cuddRotateLeft (
DdNodePtr *nodeP);
161 static void cuddRotateRight (
DdNodePtr *nodeP);
162 static void cuddDoRebalance (
DdNodePtr **stack,
int stackN);
166 static int cuddCheckCollisionOrdering (
DdManager *unique,
int i,
int j);
199 while ((
unsigned) (i * i) <= p) {
265 MMoutOfMemory = saveHandler;
274 if (unique->
stash != NULL) {
276 unique->
stash = NULL;
291 (void) fprintf(unique->
err,
292 "cuddAllocNode: out of memory");
293 (void) fprintf(unique->
err,
"Memory in use = %lu\n",
311 offset = (
ptruint) mem & (32 - 1);
312 mem += (32 - offset) /
sizeof(
DdNodePtr);
319 list[i - 1].
next = &list[i];
352 unsigned int numVars ,
353 unsigned int numVarsZ ,
354 unsigned int numSlots ,
355 unsigned int looseUpTo )
364 if (unique == NULL) {
370 cuddT(sentinel) = NULL;
371 cuddE(sentinel) = NULL;
372 sentinel->
next = NULL;
377 unique->
size = numVars;
378 unique->
sizeZ = numVarsZ;
384 while (slots < numSlots) {
390 unique->
slots = (numVars + numVarsZ + 1) * slots;
414 if (unique->
perm == NULL) {
429 if (unique->
permZ == NULL) {
449 if (unique->
stack == NULL) {
459 unique->
stack[0] = NULL;
461 #ifndef DD_NO_DEATH_ROW
482 for (i = 0; (unsigned) i < numVars; i++) {
495 if (nodelist == NULL) {
496 for (j = 0; j < i; j++) {
509 for (j = 0; (unsigned) j < slots; j++) {
510 nodelist[j] = sentinel;
515 for (i = 0; (unsigned) i < numVarsZ; i++) {
522 if (nodelist == NULL) {
523 for (j = 0; (unsigned) j < numVars; j++) {
527 for (j = 0; j < i; j++) {
539 for (j = 0; (unsigned) j < slots; j++) {
542 unique->
permZ[i] = i;
551 if (nodelist == NULL) {
552 for (j = 0; (unsigned) j < numVars; j++) {
556 for (j = 0; (unsigned) j < numVarsZ; j++) {
568 for (j = 0; (unsigned) j < slots; j++) {
576 * (
sizeof(
DdSubtable) + 2 *
sizeof(
int)) + (numVars + 1) *
579 #ifndef DD_NO_DEATH_ROW
597 unique->
treeZ = NULL;
616 unique->
out = stdout;
617 unique->
err = stderr;
626 unique->nodesDropped = 0;
627 unique->nodesFreed = 0;
630 #ifdef DD_UNIQUE_PROFILE
631 unique->uniqueLookUps = 0;
632 unique->uniqueLinks = 0;
635 unique->recursiveCalls = 0;
636 unique->swapSteps = 0;
638 unique->nextSample = 250000;
667 while (memlist != NULL) {
675 for (i = 0; i < unique->
size; i++) {
678 for (i = 0; i < unique->
sizeZ; i++) {
692 #ifndef DD_NO_DEATH_ROW
737 int i, j, deleted, totalDeleted, totalDeletedZ;
743 #ifndef DD_UNSORTED_FREE_LIST
744 #ifdef DD_RED_BLACK_FREE_LIST
748 DdNode *downTrav, *sentry;
753 #ifndef DD_NO_DEATH_ROW
758 while (hook != NULL) {
759 int res = (hook->
f)(unique,
"DD",NULL);
760 if (res == 0)
return(0);
766 while (hook != NULL) {
767 int res = (hook->
f)(unique,
"DD",NULL);
768 if (res == 0)
return(0);
782 (void) fprintf(unique->
err,
"minDead = %d\n", unique->
minDead);
792 (void) fprintf(unique->
err,
793 "garbage collecting (%d dead BDD nodes out of %d, min %d)...",
795 (void) fprintf(unique->
err,
796 " (%d dead ZDD nodes out of %d)...",
803 for (i = 0; i < slots; i++) {
805 if (c->
data != NULL) {
821 #ifndef DD_UNSORTED_FREE_LIST
822 #ifdef DD_RED_BLACK_FREE_LIST
827 for (i = 0; i < unique->
size; i++) {
833 for (j = 0; j < slots; j++) {
834 lastP = &(nodelist[j]);
836 while (node != sentinel) {
838 if (node->
ref == 0) {
840 #ifndef DD_UNSORTED_FREE_LIST
841 #ifdef DD_RED_BLACK_FREE_LIST
843 #pragma pointer_size save
844 #pragma pointer_size short
846 cuddOrderedInsert(&tree,node);
848 #pragma pointer_size restore
856 lastP = &(node->
next);
865 totalDeleted += deleted;
873 for (j = 0; j < slots; j++) {
874 lastP = &(nodelist[j]);
876 while (node != NULL) {
878 if (node->
ref == 0) {
880 #ifndef DD_UNSORTED_FREE_LIST
881 #ifdef DD_RED_BLACK_FREE_LIST
883 #pragma pointer_size save
884 #pragma pointer_size short
886 cuddOrderedInsert(&tree,node);
888 #pragma pointer_size restore
896 lastP = &(node->
next);
905 totalDeleted += deleted;
909 if ((
unsigned) totalDeleted != unique->
dead) {
912 unique->
keys -= totalDeleted;
915 unique->nodesFreed += (double) totalDeleted;
920 for (i = 0; i < unique->
sizeZ; i++) {
926 for (j = 0; j < slots; j++) {
927 lastP = &(nodelist[j]);
929 while (node != NULL) {
931 if (node->
ref == 0) {
933 #ifndef DD_UNSORTED_FREE_LIST
934 #ifdef DD_RED_BLACK_FREE_LIST
936 #pragma pointer_size save
937 #pragma pointer_size short
939 cuddOrderedInsert(&tree,node);
941 #pragma pointer_size restore
949 lastP = &(node->
next);
958 totalDeletedZ += deleted;
966 if ((
unsigned) totalDeletedZ != unique->
deadZ) {
969 unique->
keysZ -= totalDeletedZ;
972 unique->nodesFreed += (double) totalDeletedZ;
976 #ifndef DD_UNSORTED_FREE_LIST
977 #ifdef DD_RED_BLACK_FREE_LIST
982 while (memListTrav != NULL) {
987 offset = (
ptruint) memListTrav & (32 - 1);
988 memListTrav += (32 - offset) /
sizeof(
DdNodePtr);
990 downTrav = (
DdNode *)memListTrav;
993 if (downTrav[k].ref == 0) {
994 if (sentry == NULL) {
995 unique->
nextFree = sentry = &downTrav[k];
999 sentry = (sentry->
next = &downTrav[k]);
1003 memListTrav = nxtNode;
1005 sentry->
next = NULL;
1012 while (hook != NULL) {
1013 int res = (hook->
f)(unique,
"DD",NULL);
1014 if (res == 0)
return(0);
1019 (void) fprintf(unique->
err,
" done\n");
1022 return(totalDeleted+totalDeletedZ);
1143 #ifdef DD_UNIQUE_PROFILE
1144 unique->uniqueLookUps++;
1147 if (index >= unique->
size) {
1151 level = unique->
perm[index];
1161 previousP = &(nodelist[
pos]);
1162 looking = *previousP;
1164 while (T <
cuddT(looking)) {
1165 previousP = &(looking->
next);
1166 looking = *previousP;
1167 #ifdef DD_UNIQUE_PROFILE
1168 unique->uniqueLinks++;
1171 while (T ==
cuddT(looking) && E <
cuddE(looking)) {
1172 previousP = &(looking->
next);
1173 looking = *previousP;
1174 #ifdef DD_UNIQUE_PROFILE
1175 unique->uniqueLinks++;
1178 if (T ==
cuddT(looking) && E ==
cuddE(looking)) {
1179 if (looking->
ref == 0) {
1190 if (retval != 0)
return(NULL);
1192 if (retval != 0)
return(NULL);
1209 (subtable->
dead > subtable->
keys * 0.95)))) {
1219 previousP = &(nodelist[
pos]);
1220 looking = *previousP;
1222 while (T <
cuddT(looking)) {
1223 previousP = &(looking->
next);
1224 looking = *previousP;
1225 #ifdef DD_UNIQUE_PROFILE
1226 unique->uniqueLinks++;
1229 while (T ==
cuddT(looking) && E <
cuddE(looking)) {
1230 previousP = &(looking->
next);
1231 looking = *previousP;
1232 #ifdef DD_UNIQUE_PROFILE
1233 unique->uniqueLinks++;
1240 if (looking == NULL) {
1250 previousP = &(nodelist[
pos]);
1251 looking2 = *previousP;
1253 while (T <
cuddT(looking2)) {
1254 previousP = &(looking2->
next);
1255 looking2 = *previousP;
1256 #ifdef DD_UNIQUE_PROFILE
1257 unique->uniqueLinks++;
1260 while (T ==
cuddT(looking2) && E <
cuddE(looking2)) {
1261 previousP = &(looking2->
next);
1262 looking2 = *previousP;
1263 #ifdef DD_UNIQUE_PROFILE
1264 unique->uniqueLinks++;
1268 looking->
index = index;
1271 looking->
next = *previousP;
1272 *previousP = looking;
1277 cuddCheckCollisionOrdering(unique,level,pos);
1356 #ifdef DD_UNIQUE_PROFILE
1357 unique->uniqueLookUps++;
1360 if (index >= unique->
sizeZ) {
1364 level = unique->
permZ[index];
1374 (10 * subtable->
dead > 9 * subtable->
keys))) {
1383 looking = nodelist[
pos];
1385 while (looking != NULL) {
1386 if (
cuddT(looking) == T &&
cuddE(looking) == E) {
1387 if (looking->
ref == 0) {
1392 looking = looking->
next;
1393 #ifdef DD_UNIQUE_PROFILE
1394 unique->uniqueLinks++;
1403 if (retval != 0)
return(NULL);
1405 if (retval != 0)
return(NULL);
1422 if (looking == NULL)
return(NULL);
1423 looking->
index = index;
1426 looking->
next = nodelist[
pos];
1427 nodelist[
pos] = looking;
1459 #ifdef DD_UNIQUE_PROFILE
1460 unique->uniqueLookUps++;
1481 looking = nodelist[
pos];
1488 while (looking != NULL) {
1491 if (looking->
ref == 0) {
1496 looking = looking->
next;
1497 #ifdef DD_UNIQUE_PROFILE
1498 unique->uniqueLinks++;
1506 if (looking == NULL)
return(NULL);
1509 looking->
next = nodelist[
pos];
1510 nodelist[
pos] = looking;
1534 unsigned int slots, oldslots;
1535 int shift, oldshift;
1549 (void) fprintf(unique->
err,
"minDead = %d\n", unique->
minDead);
1558 (void) fprintf(unique->
err,
"minDead = %d\n", unique->
minDead);
1570 slots = oldslots << 1;
1571 shift = oldshift - 1;
1576 MMoutOfMemory = saveHandler;
1577 if (nodelist == NULL) {
1578 (void) fprintf(unique->
err,
1579 "Unable to resize subtable %d for lack of memory\n",
1583 if (unique->
stash != NULL) {
1585 unique->
stash = NULL;
1601 for (j = 0; (unsigned) j < oldslots; j++) {
1603 node = oldnodelist[j];
1604 evenP = &(nodelist[j<<1]);
1605 oddP = &(nodelist[(j<<1)+1]);
1606 while (node != sentinel) {
1611 oddP = &(node->
next);
1614 evenP = &(node->
next);
1618 *evenP = *oddP = sentinel;
1623 (void) fprintf(unique->
err,
1624 "rehashing layer %d: keys %d dead %d new size %d\n",
1638 slots = oldslots << 1;
1639 shift = oldshift - 1;
1643 MMoutOfMemory = saveHandler;
1644 if (nodelist == NULL) {
1645 (void) fprintf(unique->
err,
1646 "Unable to resize constant subtable for lack of memory\n");
1648 for (j = 0; j < unique->
size; j++) {
1658 for (j = 0; (unsigned) j < slots; j++) {
1661 for (j = 0; (unsigned) j < oldslots; j++) {
1662 node = oldnodelist[j];
1663 while (node != NULL) {
1668 nodelist[
pos] = node;
1675 (void) fprintf(unique->
err,
1676 "rehashing constants: keys %d dead %d new size %d\n",
1684 unique->
slots += (slots - oldslots);
1711 unsigned int slots, oldslots;
1717 slots = oldslots >> 1;
1721 MMoutOfMemory = saveHandler;
1722 if (nodelist == NULL) {
1730 (void) fprintf(unique->
err,
1731 "shrunk layer %d (%d keys) from %d to %d slots\n",
1735 for (j = 0; (unsigned) j < slots; j++) {
1736 nodelist[j] = sentinel;
1739 for (j = 0; (unsigned) j < oldslots; j++) {
1740 node = oldnodelist[j];
1741 while (node != sentinel) {
1746 previousP = &(nodelist[posn]);
1747 looking = *previousP;
1750 while (T <
cuddT(looking)) {
1751 previousP = &(looking->
next);
1752 looking = *previousP;
1753 #ifdef DD_UNIQUE_PROFILE
1754 unique->uniqueLinks++;
1757 while (T ==
cuddT(looking) && E <
cuddE(looking)) {
1758 previousP = &(looking->
next);
1759 looking = *previousP;
1760 #ifdef DD_UNIQUE_PROFILE
1761 unique->uniqueLinks++;
1764 node->
next = *previousP;
1771 unique->
memused += ((long) slots - (
long) oldslots) *
sizeof(
DdNode *);
1772 unique->
slots += slots - oldslots;
1804 int oldsize,newsize;
1805 int i,j,index,reorderSave;
1806 unsigned int numSlots = unique->
initSlots;
1807 int *newperm, *newinvperm, *newmap=NULL;
1814 oldsize = unique->
size;
1816 if (oldsize + n <= unique->maxSize) {
1818 for (i = oldsize - 1; i >= level; i--) {
1834 unique->
perm[index] += n;
1837 for (i = 0; i < n; i++) {
1850 unique->
perm[oldsize+i] = level + i;
1851 unique->
invperm[level+i] = oldsize + i;
1854 if (newnodelist == NULL) {
1858 for (j = 0; (unsigned) j < numSlots; j++) {
1859 newnodelist[j] = sentinel;
1862 if (unique->
map != NULL) {
1863 for (i = 0; i < n; i++) {
1864 unique->
map[oldsize+i] = oldsize + i;
1874 (void) fprintf(unique->
err,
1875 "Increasing the table size from %d to %d\n",
1880 if (newsubtables == NULL) {
1885 if (newvars == NULL) {
1891 if (newperm == NULL) {
1898 if (newinvperm == NULL) {
1905 if (unique->
map != NULL) {
1907 if (newmap == NULL) {
1920 for (i = 0; i < level; i++) {
1933 newvars[i] = unique->
vars[i];
1934 newperm[i] = unique->
perm[i];
1935 newinvperm[i] = unique->
invperm[i];
1938 for (i = level; i < oldsize; i++) {
1939 newperm[i] = unique->
perm[i];
1942 for (i = level; i < level + n; i++) {
1943 newsubtables[i].
slots = numSlots;
1944 newsubtables[i].
shift =
sizeof(int) * 8 -
1946 newsubtables[i].
keys = 0;
1948 newsubtables[i].
dead = 0;
1955 newperm[oldsize + i - level] = i;
1956 newinvperm[i] = oldsize + i - level;
1958 if (newnodelist == NULL) {
1963 for (j = 0; (unsigned) j < numSlots; j++) {
1964 newnodelist[j] = sentinel;
1968 for (i = level; i < oldsize; i++) {
1982 newvars[i] = unique->
vars[i];
1984 newinvperm[i+n] = index;
1985 newperm[index] += n;
1988 if (unique->
map != NULL) {
1989 for (i = 0; i < oldsize; i++) {
1990 newmap[i] = unique->
map[i];
1992 for (i = oldsize; i < oldsize + n; i++) {
1996 unique->
map = newmap;
2003 unique->
vars = newvars;
2005 unique->
perm = newperm;
2012 if (unique->
stack == NULL) {
2016 unique->
stack[0] = NULL;
2023 unique->
slots += n * numSlots;
2034 reorderSave = unique->
autoDyn;
2036 for (i = oldsize; i < oldsize + n; i++) {
2038 if (unique->
vars[i] == NULL) {
2039 unique->
autoDyn = reorderSave;
2041 for (j = oldsize; j < i; j++) {
2044 unique->
vars[j] = NULL;
2046 for (j = level; j < oldsize; j++) {
2070 unique->
perm[index] -= n;
2072 unique->
size = oldsize;
2073 unique->
slots -= n * numSlots;
2080 if (unique->
tree != NULL) {
2085 unique->
autoDyn = reorderSave;
2115 int firstIndex, lastIndex;
2116 int index, level, newlevel;
2122 if (n <= 0)
return(0);
2123 if (n > unique->
size) n = unique->
size;
2126 vars = unique->
vars;
2127 firstIndex = unique->
size - n;
2128 lastIndex = unique->
size;
2136 lowestLevel = unique->
size;
2137 for (index = firstIndex; index < lastIndex; index++) {
2138 level = unique->
perm[index];
2139 if (level < lowestLevel) lowestLevel = level;
2140 nodelist = subtables[level].
nodelist;
2141 if (subtables[level].
keys - subtables[level].dead != 1)
return(0);
2148 if (vars[index]->ref != 1) {
2149 if (vars[index]->ref !=
DD_MAXREF)
return(0);
2154 vars[index]->
ref = 1;
2166 for (index = firstIndex; index < lastIndex; index++) {
2167 level = unique->
perm[index];
2168 nodelist = subtables[level].
nodelist;
2175 unique->
dead -= subtables[level].
dead;
2186 for (level = lowestLevel + 1; level < unique->
size; level++) {
2187 if (subtables[level].
keys == 0) {
2191 newlevel = level - shift;
2192 subtables[newlevel].
slots = subtables[level].
slots;
2193 subtables[newlevel].
shift = subtables[level].
shift;
2194 subtables[newlevel].
keys = subtables[level].
keys;
2196 subtables[newlevel].
dead = subtables[level].
dead;
2198 index = unique->
invperm[level];
2199 unique->
perm[index] = newlevel;
2200 unique->
invperm[newlevel] = index;
2210 if (unique->
map != NULL) {
2247 int oldsize,newsize;
2248 int i,j,reorderSave;
2249 unsigned int numSlots = unique->
initSlots;
2250 int *newperm, *newinvperm;
2252 oldsize = unique->
sizeZ;
2254 if (index < unique->maxSizeZ) {
2255 for (i = oldsize; i <= index; i++) {
2262 unique->
permZ[i] = i;
2266 if (newnodelist == NULL) {
2270 for (j = 0; (unsigned) j < numSlots; j++) {
2271 newnodelist[j] = NULL;
2281 (void) fprintf(unique->
err,
2282 "Increasing the ZDD table size from %d to %d\n",
2286 if (newsubtables == NULL) {
2291 if (newperm == NULL) {
2296 if (newinvperm == NULL) {
2302 if (newsize > unique->
maxSize) {
2305 if (unique->
stack == NULL) {
2309 unique->
stack[0] = NULL;
2314 for (i = 0; i < oldsize; i++) {
2321 newperm[i] = unique->
permZ[i];
2322 newinvperm[i] = unique->
invpermZ[i];
2324 for (i = oldsize; i <= index; i++) {
2325 newsubtables[i].
slots = numSlots;
2326 newsubtables[i].
shift =
sizeof(int) * 8 -
2328 newsubtables[i].
keys = 0;
2330 newsubtables[i].
dead = 0;
2334 if (newnodelist == NULL) {
2338 for (j = 0; (unsigned) j < numSlots; j++) {
2339 newnodelist[j] = NULL;
2346 unique->
permZ = newperm;
2350 unique->
slots += (index + 1 - unique->
sizeZ) * numSlots;
2352 unique->
sizeZ = index + 1;
2392 for (i = 0; i < unique->
size; i++) {
2398 (void) fprintf(unique->
err,
"Slowing down table growth: ");
2399 (void) fprintf(unique->
err,
"GC fraction = %.2f\t", unique->
gcFrac);
2400 (void) fprintf(unique->
err,
"minDead = %u\n", unique->
minDead);
2426 unsigned int slots, oldslots;
2427 int shift, oldshift;
2438 (void) fprintf(unique->
err,
"GC fraction = %.2f\t",
2440 (void) fprintf(unique->
err,
"minDead = %d\n", unique->
minDead);
2459 }
while (slots * DD_MAX_SUBTABLE_DENSITY < unique->subtableZ[i].
keys);
2464 MMoutOfMemory = saveHandler;
2465 if (nodelist == NULL) {
2466 (void) fprintf(unique->
err,
2467 "Unable to resize ZDD subtable %d for lack of memory.\n",
2470 for (j = 0; j < unique->
sizeZ; j++) {
2479 for (j = 0; (unsigned) j < slots; j++) {
2482 for (j = 0; (unsigned) j < oldslots; j++) {
2483 node = oldnodelist[j];
2484 while (node != NULL) {
2488 nodelist[
pos] = node;
2495 (void) fprintf(unique->
err,
2496 "rehashing layer %d: keys %d dead %d new size %d\n",
2503 unique->
slots += (slots - oldslots);
2531 int oldsize,newsize;
2532 int i,j,reorderSave;
2534 int *newperm, *newinvperm, *newmap = NULL;
2537 oldsize = unique->
size;
2539 if (index < unique->maxSize) {
2540 for (i = oldsize; i <= index; i++) {
2553 unique->
perm[i] = i;
2557 if (newnodelist == NULL) {
2558 for (j = oldsize; j < i; j++) {
2564 for (j = 0; j < numSlots; j++) {
2565 newnodelist[j] = sentinel;
2568 if (unique->
map != NULL) {
2569 for (i = oldsize; i <= index; i++) {
2580 (void) fprintf(unique->
err,
2581 "Increasing the table size from %d to %d\n",
2585 if (newsubtables == NULL) {
2590 if (newvars == NULL) {
2596 if (newperm == NULL) {
2603 if (newinvperm == NULL) {
2610 if (unique->
map != NULL) {
2612 if (newmap == NULL) {
2627 if (unique->
stack == NULL) {
2632 if (unique->
map != NULL) {
2638 unique->
stack[0] = NULL;
2643 for (i = 0; i < oldsize; i++) {
2656 newvars[i] = unique->
vars[i];
2657 newperm[i] = unique->
perm[i];
2658 newinvperm[i] = unique->
invperm[i];
2660 for (i = oldsize; i <= index; i++) {
2661 newsubtables[i].
slots = numSlots;
2662 newsubtables[i].
shift =
sizeof(int) * 8 -
2664 newsubtables[i].
keys = 0;
2666 newsubtables[i].
dead = 0;
2676 if (newnodelist == NULL) {
2680 for (j = 0; j < numSlots; j++) {
2681 newnodelist[j] = sentinel;
2684 if (unique->
map != NULL) {
2685 for (i = 0; i < oldsize; i++) {
2686 newmap[i] = unique->
map[i];
2688 for (i = oldsize; i <= index; i++) {
2692 unique->
map = newmap;
2698 unique->
vars = newvars;
2700 unique->
perm = newperm;
2712 unique->
size = index + 1;
2713 unique->
slots += (index + 1 - oldsize) * numSlots;
2716 reorderSave = unique->
autoDyn;
2718 for (i = oldsize; i <= index; i++) {
2720 if (unique->
vars[i] == NULL) {
2721 unique->
autoDyn = reorderSave;
2722 for (j = oldsize; j < i; j++) {
2725 unique->
vars[j] = NULL;
2727 for (j = oldsize; j <= index; j++) {
2731 unique->
size = oldsize;
2732 unique->
slots -= (index + 1 - oldsize) * numSlots;
2738 unique->
autoDyn = reorderSave;
2767 for (i =
cuddI(table,node->
index) - 1; i >= 0; i--) {
2771 for (j = 0; j < slots; j++) {
2773 while (
cuddT(f) > node) {
2819 #ifndef DD_UNSORTED_FREE_LIST
2820 #ifdef DD_RED_BLACK_FREE_LIST
2844 while ((scan = *scanP) != NULL) {
2845 stack[stackN++] = scanP;
2846 if (DD_INSERT_COMPARE(node, scan) == 0) {
2847 DD_NEXT(node) = DD_NEXT(scan);
2848 DD_NEXT(scan) = node;
2851 scanP = (node < scan) ? &DD_LEFT(scan) : &DD_RIGHT(scan);
2853 DD_RIGHT(node) = DD_LEFT(node) = DD_NEXT(node) = NULL;
2854 DD_COLOR(node) = DD_RED;
2856 stack[stackN] = &node;
2857 cuddDoRebalance(stack,stackN);
2887 DdNode *current, *next, *prev, *end;
2896 while (current != NULL) {
2897 if (DD_RIGHT(current) != NULL) {
2905 next = DD_RIGHT(current);
2906 DD_RIGHT(current) = NULL;
2918 for (end = current; DD_NEXT(end) != NULL; end = DD_NEXT(end));
2919 DD_NEXT(end) = list;
2924 if (DD_LEFT(current) != NULL) {
2925 next = DD_LEFT(current);
2956 DdNode *oldRoot = *nodeP;
2958 *nodeP = newRoot = DD_RIGHT(oldRoot);
2959 DD_RIGHT(oldRoot) = DD_LEFT(newRoot);
2960 DD_LEFT(newRoot) = oldRoot;
2982 DdNode *oldRoot = *nodeP;
2984 *nodeP = newRoot = DD_LEFT(oldRoot);
2985 DD_LEFT(oldRoot) = DD_RIGHT(newRoot);
2986 DD_RIGHT(newRoot) = oldRoot;
3008 DdNode *x, *y, *parent, *grandpa;
3013 while (--stackN >= 0) {
3014 parentP = stack[stackN];
3016 if (DD_IS_BLACK(parent))
break;
3018 grandpaP = stack[stackN-1];
3019 grandpa = *grandpaP;
3020 if (parent == DD_LEFT(grandpa)) {
3021 y = DD_RIGHT(grandpa);
3022 if (y != NULL && DD_IS_RED(y)) {
3023 DD_COLOR(parent) = DD_BLACK;
3024 DD_COLOR(y) = DD_BLACK;
3025 DD_COLOR(grandpa) = DD_RED;
3029 if (x == DD_RIGHT(parent)) {
3030 cuddRotateLeft(parentP);
3031 DD_COLOR(x) = DD_BLACK;
3033 DD_COLOR(parent) = DD_BLACK;
3035 DD_COLOR(grandpa) = DD_RED;
3036 cuddRotateRight(grandpaP);
3040 y = DD_LEFT(grandpa);
3041 if (y != NULL && DD_IS_RED(y)) {
3042 DD_COLOR(parent) = DD_BLACK;
3043 DD_COLOR(y) = DD_BLACK;
3044 DD_COLOR(grandpa) = DD_RED;
3048 if (x == DD_LEFT(parent)) {
3049 cuddRotateRight(parentP);
3050 DD_COLOR(x) = DD_BLACK;
3052 DD_COLOR(parent) = DD_BLACK;
3054 DD_COLOR(grandpa) = DD_RED;
3055 cuddRotateLeft(grandpaP);
3059 DD_COLOR(*(stack[0])) = DD_BLACK;
3086 while (auxnode != NULL) {
3088 if (auxnode->
child != NULL) {
3112 cuddCheckCollisionOrdering(
3125 if (node == sentinel)
return(1);
3127 while (next != sentinel) {
3130 (void) fprintf(unique->
err,
3131 "Unordered list: index %u, position %d\n", i, j);
3160 const char *caller )
3163 (void) fprintf(unique->
err,
3164 "%s: problem in constants\n", caller);
3165 }
else if (i != -1) {
3166 (void) fprintf(unique->
err,
3167 "%s: problem in table %d\n", caller, i);
3169 (void) fprintf(unique->
err,
" dead count != deleted\n");
3170 (void) fprintf(unique->
err,
" This problem is often due to a missing \
3171 call to Cudd_Ref\n or to an extra call to Cudd_RecursiveDeref.\n \
3172 See the CUDD Programmer's Guide for additional details.");
static void ddReportRefMess(DdManager *unique, int i, const char *caller)
void Cudd_IterDerefBdd(DdManager *table, DdNode *n)
unsigned int Cudd_Prime(unsigned int p)
Cudd_AggregationType groupcheck
void cuddCacheFlush(DdManager *table)
void Cudd_RecursiveDerefZdd(DdManager *table, DdNode *n)
int cuddZddInitUniv(DdManager *zdd)
void Cudd_OutOfMem(long size)
Cudd_ReorderingType autoMethod
#define cuddIZ(dd, index)
unsigned int peakLiveNodes
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
static void ddPatchTree(DdManager *dd, MtrNode *treenode)
DdHook * preReorderingHook
struct DdManager DdManager
unsigned int maxCacheHard
DdNode * cuddUniqueConst(DdManager *unique, CUDD_VALUE_TYPE value)
#define Cudd_Regular(node)
void cuddReclaim(DdManager *table, DdNode *n)
void cuddShrinkSubtable(DdManager *unique, int i)
void Mtr_FreeTree(MtrNode *node)
#define ABC_ALLOC(type, num)
Cudd_ReorderingType autoMethodZ
struct DdSubtable DdSubtable
#define DD_MAX_SUBTABLE_DENSITY
#define DD_DEFAULT_RECOMB
static char rcsid[] DD_UNUSED
Cudd_VariableType varType
void cuddFreeTable(DdManager *unique)
DdNode * cuddUniqueInterIVO(DdManager *unique, int index, DdNode *T, DdNode *E)
DdNode * cuddZddProduct(DdManager *dd, DdNode *f, DdNode *g)
int cuddDestroySubtables(DdManager *unique, int n)
int cuddResizeTableZdd(DdManager *unique, int index)
DdHook * postReorderingHook
int cuddGarbageCollect(DdManager *unique, int clearCache)
#define DD_SIFT_MAX_SWAPS
Cudd_LazyGroupType varToBeGrouped
int cuddComputeFloorLog2(unsigned int value)
static int cuddFindParent(DdManager *table, DdNode *node)
void cuddZddFreeUniv(DdManager *zdd)
void cuddRehash(DdManager *unique, int i)
#define ABC_NAMESPACE_IMPL_END
int cuddInsertSubtables(DdManager *unique, int n, int level)
static int ddResizeTable(DdManager *unique, int index)
int Cudd_DebugCheck(DdManager *table)
DdLocalCache * localCaches
#define DD_MAX_CACHE_TO_SLOTS_RATIO
static void ddRehashZdd(DdManager *unique, int i)
void cuddLocalCacheClearDead(DdManager *manager)
#define cuddDeallocNode(unique, node)
void cuddReclaimZdd(DdManager *table, DdNode *n)
int Cudd_RemoveHook(DdManager *dd, DD_HFP f, Cudd_HookType where)
#define ddEqualVal(x, y, e)
DdNode * cuddZddGetNode(DdManager *zdd, int id, DdNode *T, DdNode *E)
#define ABC_NAMESPACE_IMPL_START
void cuddSlowTableGrowth(DdManager *unique)
int Cudd_zddReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)
DdNode * cuddZddUnion(DdManager *zdd, DdNode *P, DdNode *Q)
#define DD_DEFAULT_RESIZE
void cuddClearDeathRow(DdManager *table)
ABC_NAMESPACE_IMPL_START union hack hack
int Cudd_CheckKeys(DdManager *table)
#define DD_MAX_REORDER_GROWTH
static DD_INLINE void ddFixLimits(DdManager *unique)
DdNode * cuddZddGetNodeIVO(DdManager *dd, int index, DdNode *g, DdNode *h)
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
DdManager * cuddInitTable(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int looseUpTo)
int Cudd_ReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)
DdNode * cuddUniqueInterZdd(DdManager *unique, int index, DdNode *T, DdNode *E)
void cuddShrinkDeathRow(DdManager *table)
DdNode * cuddAllocNode(DdManager *unique)
void cuddCacheResize(DdManager *table)
DdNode * cuddBddIteRecur(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)