Skip to content

Commit

Permalink
Convert orderInfo array to a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatilai committed May 8, 2024
1 parent 5cc2276 commit 16759ef
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/order.c
Expand Up @@ -364,18 +364,17 @@ static void tarjan(sccData sd, tsortInfo tsi)
}

/* Search for SCCs and return an array last entry has a .size of 0 */
static scc detectSCCs(tsortInfo orderInfo, int nelem, int debugloops)
static scc detectSCCs(std::vector<tsortInfo_s> & orderInfo, int debugloops)
{
/* Set up data structures needed for the tarjan algorithm */
scc SCCs = (scc)xcalloc(nelem+3, sizeof(*SCCs));
tsortInfo *stack = (tsortInfo *)xcalloc(nelem, sizeof(*stack));
scc SCCs = (scc)xcalloc(orderInfo.size()+3, sizeof(*SCCs));
tsortInfo *stack = (tsortInfo *)xcalloc(orderInfo.size(), sizeof(*stack));
struct sccData_s sd = { 0, stack, 0, SCCs, 2 };

for (int i = 0; i < nelem; i++) {
tsortInfo tsi = &orderInfo[i];
for (auto & tsi : orderInfo) {
/* Start a DFS at each node */
if (tsi->tsi_SccIdx == 0)
tarjan(&sd, tsi);
if (tsi.tsi_SccIdx == 0)
tarjan(&sd, &tsi);
}

free(stack);
Expand Down Expand Up @@ -583,7 +582,7 @@ int rpmtsOrder(rpmts ts)
rpmal erasedPackages;
scc SCCs;
int nelem = rpmtsNElements(ts);
tsortInfo sortInfo = (tsortInfo)xcalloc(nelem, sizeof(struct tsortInfo_s));
std::vector<tsortInfo_s> sortInfo(nelem);

(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_ORDER), 0);

Expand Down Expand Up @@ -621,7 +620,7 @@ int rpmtsOrder(rpmts ts)
rpmtsiFree(pi);

std::vector<rpmte> newOrder;
SCCs = detectSCCs(sortInfo, nelem, (rpmtsFlags(ts) & RPMTRANS_FLAG_DEPLOOPS));
SCCs = detectSCCs(sortInfo, (rpmtsFlags(ts) & RPMTRANS_FLAG_DEPLOOPS));

rpmlog(RPMLOG_DEBUG, "========== tsorting packages (order, #predecessors, #succesors, depth)\n");

Expand Down Expand Up @@ -673,7 +672,6 @@ int rpmtsOrder(rpmts ts)
rpmteSetTSI(tsmem->order[i], NULL);
rpmTSIFree(&sortInfo[i]);
}
free(sortInfo);

assert(newOrder.size() == tsmem->order.size());

Expand Down

0 comments on commit 16759ef

Please sign in to comment.