From c2aedcebabf46f6764f8dc9e6fbcfdf6ed418175 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Mon, 22 Mar 2021 09:49:56 -0400 Subject: [PATCH] Applied the same change made yesterday to DBconnect.c to ResConDCS.c and SimDBstuff.c, which have nearly the same connectivity search functions. All three now use the hybrid list + stack method. --- VERSION | 2 +- database/DBconnect.c | 2 -- resis/ResConDCS.c | 61 +++++++++++++++++++++++++++++--------------- sim/SimDBstuff.c | 56 +++++++++++++++++++++++++++------------- 4 files changed, 79 insertions(+), 42 deletions(-) diff --git a/VERSION b/VERSION index c8e7cc7e..6a0e5078 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.3.145 +8.3.146 diff --git a/database/DBconnect.c b/database/DBconnect.c index 3ea3bee9..950c8d45 100644 --- a/database/DBconnect.c +++ b/database/DBconnect.c @@ -84,7 +84,6 @@ struct conSrArg2 * to what. */ SearchContext *csa2_topscx; /* Original top-level search context */ - int csa2_xMask; /* Cell window mask for search */ Rect *csa2_bounds; /* Area that limits the search */ Stack *csa2_stack; /* Stack of full csa2_list entries */ @@ -1053,7 +1052,6 @@ DBTreeCopyConnect(scx, mask, xMask, connect, area, doLabels, destUse) unsigned char searchtype; csa2.csa2_use = destUse; - csa2.csa2_xMask = xMask; csa2.csa2_bounds = area; csa2.csa2_connect = connect; csa2.csa2_topscx = scx; diff --git a/resis/ResConDCS.c b/resis/ResConDCS.c index a150cfb8..c8591f97 100644 --- a/resis/ResConDCS.c +++ b/resis/ResConDCS.c @@ -17,6 +17,7 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/ #include "utils/geofast.h" #include "tiles/tile.h" #include "utils/hash.h" +#include "utils/stack.h" #include "database/database.h" #include "utils/malloc.h" #include "textio/textio.h" @@ -46,12 +47,13 @@ struct conSrArg2 int csa2_xMask; /* Cell window mask for search */ Rect *csa2_bounds; /* Area that limits the search */ + Stack *csa2_stack; /* Stack of full csa2_list entries */ conSrArea *csa2_list; /* List of areas to process */ int csa2_top; /* Index of next area to process */ - int csa2_size; /* Max. number bins in area list */ + int csa2_lasttop; /* Previous top index */ }; -#define CSA2_LIST_START_SIZE 256 +#define CSA2_LIST_SIZE 65536 /* Number of entries per list */ extern int dbcUnconnectFunc(); extern int dbcConnectLabelFunc(); @@ -100,7 +102,7 @@ dbcConnectFuncDCS(tile, cx) TileType dinfo = 0; SearchContext *scx = cx->tc_scx; SearchContext scx2; - int pNum; + int i, pNum; CellDef *def; ExtDevice *devptr; TerminalPath tpath; @@ -296,29 +298,29 @@ dbcConnectFuncDCS(tile, cx) newarea.r_ytop += 1; } + /* Check if any of the last 5 entries has the same type and */ + /* area. If so, don't duplicate the existing entry. */ + /* (NOTE: Connect masks are all from the same table, so */ + /* they can be compared by address, no need for TTMaskEqual)*/ + + for (i = csa2->csa2_lasttop; (i >= 0) && (i > csa2->csa2_lasttop - 5); i--) + if (connectMask == csa2->csa2_list[i].connectMask) + if (GEO_SURROUND(&csa2->csa2_list[i].area, &newarea)) + return 0; + /* Register the area and connection mask as needing to be processed */ - if (++csa2->csa2_top == csa2->csa2_size) + if (++csa2->csa2_top == CSA2_LIST_SIZE) { /* Reached list size limit---need to enlarge the list */ /* Double the size of the list every time we hit the limit */ conSrArea *newlist; - int i, lastsize = csa2->csa2_size; - csa2->csa2_size *= 2; - - newlist = (conSrArea *)mallocMagic(csa2->csa2_size * sizeof(conSrArea)); - memcpy((void *)newlist, (void *)csa2->csa2_list, - (size_t)lastsize * sizeof(conSrArea)); - // for (i = 0; i < lastsize; i++) - // { - // newlist[i].area = csa2->csa2_list[i].area; - // newlist[i].connectMask = csa2->csa2_list[i].connectMask; - // newlist[i].dinfo = csa2->csa2_list[i].dinfo; - // } - freeMagic((char *)csa2->csa2_list); + newlist = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea)); + StackPush((ClientData)csa2->csa2_list, csa2->csa2_stack); csa2->csa2_list = newlist; + csa2->csa2_top = 0; } csa2->csa2_list[csa2->csa2_top].area = newarea; @@ -443,10 +445,11 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse) csa2.csa2_connect = connect; csa2.csa2_topscx = scx; - csa2.csa2_size = CSA2_LIST_START_SIZE; - csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_START_SIZE - * sizeof(conSrArea)); + csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea)); csa2.csa2_top = -1; + csa2.csa2_lasttop = -1; + + csa2.csa2_stack = StackNew(100); if (first) { @@ -474,7 +477,22 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse) newmask = csa2.csa2_list[csa2.csa2_top].connectMask; scx->scx_area = csa2.csa2_list[csa2.csa2_top].area; newtype = csa2.csa2_list[csa2.csa2_top].dinfo; - csa2.csa2_top--; + if (csa2.csa2_top == 0) + { + if (StackLook(csa2.csa2_stack) != (ClientData)NULL) + { + freeMagic(csa2.csa2_list); + csa2.csa2_list = (conSrArea *)StackPop(csa2.csa2_stack); + csa2.csa2_top = CSA2_LIST_SIZE - 1; + } + else + csa2.csa2_top--; + } + else + csa2.csa2_top--; + + csa2.csa2_lasttop = csa2.csa2_top; + if (newtype & TT_DIAGONAL) DBTreeSrNMTiles(scx, newtype, newmask, xMask, dbcConnectFuncDCS, (ClientData) &csa2); @@ -482,6 +500,7 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse) DBTreeSrTiles(scx, newmask, xMask, dbcConnectFuncDCS, (ClientData) &csa2); } freeMagic((char *)csa2.csa2_list); + StackFree(csa2.csa2_stack); for (CurrentT = DevList; CurrentT != NULL; CurrentT=CurrentT->nextDev) { diff --git a/sim/SimDBstuff.c b/sim/SimDBstuff.c index 840d749f..b303d4e6 100644 --- a/sim/SimDBstuff.c +++ b/sim/SimDBstuff.c @@ -31,6 +31,7 @@ #include "utils/geofast.h" #include "tiles/tile.h" #include "utils/hash.h" +#include "utils/stack.h" #include "database/database.h" #include "database/databaseInt.h" #include "textio/textio.h" @@ -86,12 +87,13 @@ struct conSrArg2 */ Rect *csa2_bounds; /* Area that limits the search */ + Stack *csa2_stack; /* Stack of full csa2_list entries */ conSrArea *csa2_list; /* List of areas to process */ int csa2_top; /* Index of next area to process */ - int csa2_size; /* Max. number bins in area list */ + int csa2_lasttop; /* Previous top index */ }; -#define CSA2_LIST_START_SIZE 256 +#define CSA2_LIST_SIZE 65536 /* Number of entries per list */ /* Forward declarations */ @@ -303,27 +305,29 @@ SimConnectFunc(tile, cx) return 1; } + /* Check if any of the last 5 entries has the same type and */ + /* area. If so, don't duplicate the existing entry. */ + /* (NOTE: Connect masks are all from the same table, so */ + /* they can be compared by address, no need for TTMaskEqual)*/ + + for (i = csa2->csa2_lasttop; (i >= 0) && (i > csa2->csa2_lasttop - 5); i--) + if (connectMask == csa2->csa2_list[i].connectMask) + if (GEO_SURROUND(&csa2->csa2_list[i].area, &newarea)) + return 0; + /* Register the area and connection mask as needing to be processed */ - if (++csa2->csa2_top == csa2->csa2_size) + if (++csa2->csa2_top == CSA2_LIST_SIZE) { /* Reached list size limit---need to enlarge the list */ /* Double the size of the list every time we hit the limit */ conSrArea *newlist; - int i, lastsize = csa2->csa2_size; - csa2->csa2_size *= 2; - - newlist = (conSrArea *)mallocMagic(csa2->csa2_size * sizeof(conSrArea)); - for (i = 0; i < lastsize; i++) - { - newlist[i].area = csa2->csa2_list[i].area; - newlist[i].connectMask = csa2->csa2_list[i].connectMask; - newlist[i].dinfo = csa2->csa2_list[i].dinfo; - } - freeMagic((char *)csa2->csa2_list); + newlist = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea)); + StackPush((ClientData)csa2->csa2_list, csa2->csa2_stack); csa2->csa2_list = newlist; + csa2->csa2_top = 0; } csa2->csa2_list[csa2->csa2_top].area = newarea; @@ -407,10 +411,11 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name) csa2.csa2_bounds = area; csa2.csa2_connect = connect; - csa2.csa2_size = CSA2_LIST_START_SIZE; - csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_START_SIZE - * sizeof(conSrArea)); + csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea)); csa2.csa2_top = -1; + csa2.csa2_lasttop = -1; + + csa2.csa2_stack = StackNew(100); tpath.tp_first = tpath.tp_next = pathName; tpath.tp_last = pathName + MAXPATHNAME; @@ -425,7 +430,21 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name) newmask = csa2.csa2_list[csa2.csa2_top].connectMask; scx->scx_area = csa2.csa2_list[csa2.csa2_top].area; newtype = csa2.csa2_list[csa2.csa2_top].dinfo; - csa2.csa2_top--; + if (csa2.csa2_top == 0) + { + if (StckLook(csa2.csa2_stack) != (ClientData)NULL) + { + freeMagic(csa2.csa2_list); + csa2.csa2_list = (conSrArea *)StackPop(csa2.csa2_stack); + csa2.csa2_top = CSA2_LIST_SIZE - 1; + } + else + csa2.csa2_top--; + } + else + csa2.csa2_top--; + + csa2.csa2_lasttop = csa2.csa2_top; if (newtype & TT_DIAGONAL) SimTreeSrNMTiles(scx, newtype, newmask, xMask, &tpath, @@ -435,6 +454,7 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name) (ClientData) &csa2); } freeMagic((char *)csa2.csa2_list); + StackFree(csa2.csa2_stack); /* Recompute the bounding box of the destination and record * its area for redisplay.