void CBlockEvaluator::Attach(bool AllowStateSemantics, CReactionBase * pRB, CHXBase *pHX, CEnvironHXBase * pEHX, CVLEBase * pVLE, CEvapBase * pEvap) { m_nBlocks = 0; m_bAllowStateSemantics = AllowStateSemantics; m_pRB = pRB; m_pHX = pHX; m_pEHX = pEHX; m_pVLE = pVLE; m_pEvap = pEvap; AddBlk(m_pRB, MaxNdMakeups+2); AddBlk(m_pHX, MaxNdMakeups+3); AddBlk(m_pEHX, MaxNdMakeups+4); AddBlk(m_pVLE, MaxNdMakeups+5); AddBlk(m_pEvap, MaxNdMakeups+6); m_nMaxNdMakeups = MaxNdMakeups; SortBlocks(); };
void CBlockEvaluator::SetMakeupCount(int N, bool MakeConnects) { if (N!=m_pMakeups.GetSize()) { N=Range(0, N, m_nMaxNdMakeups); for (int a=N; a<m_pMakeups.GetSize(); a++) { //m_pMakeups[a]->SetEnable(false); m_pNd->DoDirectDisConnect(&m_pMakeups[a]->m_SrcIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); //m_pMakeups[a]->m_SrcIO.ManageNdDirectIOs(false); RemBlk(m_pMakeups[a]); delete m_pMakeups[a]; } int NOld=m_pMakeups.GetSize(); m_pMakeups.SetSize(N); for (int a=NOld; a<N; a++) { Strng Tg, Nm; Tg.Set("%s%i", MakeupIOTag, a+1); m_pMakeups[a] = new CMakeupBase(m_pNd, a, Tg()); m_pMakeups[a]->Open(1); m_pMakeups[a]->SetEnable(true); if (MakeConnects) m_pNd->DoDirectConnect(&m_pMakeups[a]->m_SrcIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); AddBlk(m_pMakeups[a], 1+a); } SortBlocks(); } }
void CBlockEvaluator::SetBleedCount(int N, bool MakeConnects) { if (N!=m_pBleeds.GetSize()) { N=Range(0, N, MaxNdBleeds); for (int a=N; a<m_pBleeds.GetSize(); a++) { m_pNd->DoDirectDisConnect(&m_pBleeds[a]->m_SnkIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); RemBlk(m_pBleeds[a]); delete m_pBleeds[a]; } int NOld=m_pBleeds.GetSize(); m_pBleeds.SetSize(N); for (int a=NOld; a<N; a++) { Strng Tg, Nm; Tg.Set("%s%i", BleedIOTag, a+1); m_pBleeds[a] = new CBleedBase(m_pNd, a, Tg()); m_pBleeds[a]->Open(1); m_pBleeds[a]->SetEnable(true); if (MakeConnects) m_pNd->DoDirectConnect(&m_pBleeds[a]->m_SnkIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); AddBlk(m_pBleeds[a], MaxNdMakeups*2+a); } SortBlocks(); } }
static void *SetBlk(void *Blk, size_t size, const char *file) #endif { ((begin *)Blk)->StpA = PREV_STOP; #ifdef GENERATIONS ((begin *)Blk)->Generation = ++cur_generation; #endif ((begin *)Blk)->File = file; ((begin *)Blk)->Size = size; #ifdef WITH_FLAGS ((begin *)Blk)->Flags = flags; #endif ((begin *)Blk)->StpB = PREV_STOP; memcpy(((char *)Blk)+START_SPACE+size, End, END_SPACE); #if RM_TEST_DEPTH > 0 AddBlk((begin *)Blk, file); #endif #ifdef ELOQUENT fprintf(stderr, HEAD "Adding: %p, %d Bytes (from %s)\n", ((char *)Blk)+START_SPACE, size, file); #endif /* ELOQUENT */ #ifdef GENERATIONS if (BREAK_GENERATION_COND(cur_generation)) { rmalloc_generation(Blk); } #endif return ((char *)Blk)+START_SPACE; }
long cCBLKFindCommonLines( long iLine1Start, long iLine2Start, long iLine1Mac, long iLine2Mac) { HE *phe; FH *pfh1; FH *pfh2; long iLine1, iLine2; long cLineBlock; long iBlk; CBLK *pBlk; long cCBlkFinalprev = cCBlkFinal; BOOL fFoundUnique; /* limit ourselves to the end of the file */ if (iLine1Mac > fdd1.iLineEOF) iLine1Mac = fdd1.iLineEOF; if (iLine2Mac > fdd2.iLineEOF) iLine2Mac = fdd2.iLineEOF; /* initialize each HE corresponding to a line's hash value */ InitHE(&fdd2, iLine2Start, iLine2Mac); InitHE(&fdd1, iLine1Start, iLine1Mac); /* mark each instance of a line in rghe - legal values are: 0, 1, many (2) */ for (iLine2 = iLine2Start, pfh2 = &fdd2.rgfh[iLine2Start]; iLine2 < iLine2Mac; iLine2++, pfh2++) { phe = pfh2->phe; if (phe->cLine2 < 2) phe->cLine2++; } /* mark each instance of a line in rghe - legal values are: 0, 1, many (2) * also save the file 1 line number */ for (iLine1 = iLine1Start, pfh1 = &fdd1.rgfh[iLine1Start]; iLine1 < iLine1Mac; iLine1++, pfh1++) { phe = pfh1->phe; if (phe->cLine1 < 2) phe->cLine1++; phe->iLine1 = iLine1; } /* now walk through rgfh looking for lines that occur only * once in this block - this provides an "anchor point" where we * decide these two lines MUST be matching lines * we then go into each line's rgfh entry and point it * at the other file's matching line */ for (fFoundUnique = fFalse, iLine2 = iLine2Start, pfh2 = &fdd2.rgfh[iLine2Start]; iLine2 < iLine2Mac; iLine2++, pfh2++) { phe = pfh2->phe; if ((1 == phe->cLine1) && (1 == phe->cLine2)) { iLine1 = phe->iLine1; pfh2->u.iLineMatch = iLine1; pfh2->fLineMatch = fTrue; fdd1.rgfh[iLine1].u.iLineMatch = iLine2; fdd1.rgfh[iLine1].fLineMatch = fTrue; fFoundUnique = fTrue; } } if (!fFoundUnique) { /* panic mode: no unique lines were found! * since iLine1 in each HE element will be set to the * LAST time it occurred in the 1st file, we walk back from * the end of the 2nd file's block and arbitrarily pick * matching lines in the 2nd file as "anchor points" just like * we would have if they were lines that occurred only once * in each block */ for (iLine2 = iLine2Mac - 1, pfh2 = &fdd2.rgfh[iLine2Mac - 1]; iLine2 >= iLine2Start; iLine2--, pfh2--) { phe = pfh2->phe; if ((phe->cLine1 > 0) && (phe->cLine2 > 0)) { iLine1 = phe->iLine1; if (!fdd1.rgfh[iLine1].fLineMatch) { pfh2->u.iLineMatch = iLine1; pfh2->fLineMatch = fTrue; fdd1.rgfh[iLine1].u.iLineMatch = iLine2; fdd1.rgfh[iLine1].fLineMatch = fTrue; } } } } /* now walk forward from each "anchor point" and assume that if * the next lines from each file have the same hash value, then * they must be the same line and treat them as if we had another * "anchor point". continue walking forward matching lines until * we hit another "anchor point" or the lines don't share the same * hash value. then start over looking for the next "anchor point", * etc. until we run into the end of the block */ for (iLine2 = iLine2Start, pfh2 = &fdd2.rgfh[iLine2Start]; iLine2 < iLine2Mac;) { if (pfh2->fLineMatch) { if ((iLine1 = pfh2->u.iLineMatch + 1) < iLine1Mac) { pfh1 = &fdd1.rgfh[iLine1]; iLine2++; pfh2++; for (; (iLine1 < iLine1Mac) && (iLine2 < iLine2Mac); iLine1++, iLine2++, pfh1++, pfh2++) { if (pfh1->fLineMatch || pfh2->fLineMatch || (pfh1->phe != pfh2->phe)) break; pfh2->u.iLineMatch = iLine1; pfh2->fLineMatch = fTrue; pfh1->u.iLineMatch = iLine2; pfh1->fLineMatch = fTrue; } continue; } } iLine2++; pfh2++; } /* now we do exactly what we just did above only this time we * walk backwards from the end of each block */ iLine2 = iLine2Mac - 1; for (pfh2 = &fdd2.rgfh[iLine2]; iLine2 > iLine2Start;) { if (pfh2->fLineMatch) { if ((iLine1 = pfh2->u.iLineMatch - 1) >= iLine1Start) { pfh1 = &fdd1.rgfh[iLine1]; iLine2--; pfh2--; for (; (iLine1 >= iLine1Start) && (iLine2 >= iLine2Start); iLine1--, iLine2--, pfh1--, pfh2--) { if (pfh1->fLineMatch || pfh2->fLineMatch || (pfh1->phe != pfh2->phe)) break; pfh2->u.iLineMatch = iLine1; pfh2->fLineMatch = fTrue; pfh1->u.iLineMatch = iLine2; pfh1->fLineMatch = fTrue; } continue; } } iLine2--; pfh2--; } /* find the start point of each common block and its size and register * each candidate in rgCBlkCand */ for (iLine1 = iLine1Start, iLine2 = iLine2Start, cCBlkCand = 0, pfh2 = &fdd2.rgfh[iLine2Start]; iLine2 < iLine2Mac;) { cLineBlock = 0; if (pfh2->fLineMatch) { iLine1 = pfh2->u.iLineMatch; while (pfh2->fLineMatch) { iLine1++; iLine2++; if (iLine2 < fdd2.iLineEOF) { pfh2++; if (pfh2->fLineMatch) pfh1 = &fdd1.rgfh[pfh2->u.iLineMatch]; } cLineBlock++; if (!pfh2->fLineMatch || (pfh1->u.iLineMatch != iLine2) || (pfh2->u.iLineMatch != iLine1) || (iLine2 >= iLine2Mac)) { LogCBlkCand(iLine1, iLine2, cLineBlock); break; } } } else { iLine2++; pfh2++; } } #ifdef DEBUGPRINT /* print out a list of the candidiate group of common blocks */ printf("\n"); for (iBlk = 0, pBlk = &rgCBlkCand[0]; iBlk < cCBlkCand; iBlk++, pBlk++) { printf("Cand common block: iLine1 = %ld iLine2 = %ld cLine = %ld\r\n", pBlk->iLine1, pBlk->iLine2, pBlk->cLine); } printf("\n"); #endif /* sort the common blocks keyed on size of block */ qsort(rgCBlkCand, (size_t)cCBlkCand, (size_t)(sizeof (CBLK)), (int (*)(const void *, const void *))CBlkCmp); /* from largest to smallest block add the blocks to the rgCBlkFinal array */ for (iBlk = 0, pBlk = rgCBlkCand; iBlk < cCBlkCand; iBlk++, pBlk++) AddBlk(pBlk); /* return number of new blocks discovered */ return (cCBlkFinal - cCBlkFinalprev); }