Skip to content

Commit

Permalink
Fix CacheTableTwo tests depend on static internal functions (closes #28)
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Feb 9, 2024
1 parent 3026400 commit 1eb854d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
101 changes: 50 additions & 51 deletions src/calCacheTableTwo.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ struct CacheEntryStruct {
/* Static function prototypes */
/*---------------------------------------------------------------------------*/

static void CacheTableTwoRehash(CalCacheTable_t *cacheTable, int grow);
static void CacheTablePrint(CalCacheTable_t *cacheTable);

/**AutomaticEnd***************************************************************/
Expand Down Expand Up @@ -161,6 +160,56 @@ CalCacheTableTwoInit(Cal_BddManager_t *bddManager)
return cacheTable;
}

/**Function********************************************************************
Reshash Cacch table (if desired, while also growing the table).
******************************************************************************/
void
CacheTableTwoRehash(CalCacheTable_t *cacheTable, int grow)
{
CacheEntry_t *oldBins = cacheTable->bins;
int i, hashValue;
int oldNumBins = cacheTable->numBins;
CacheEntry_t *bin, *newBin;


if(grow){
cacheTable->sizeIndex++;
}
else{
if (cacheTable->sizeIndex <= CACHE_TABLE_DEFAULT_SIZE_INDEX){/* No need to Rehash */
return;
}
cacheTable->sizeIndex--;
}

cacheTable->numBins = TABLE_SIZE(cacheTable->sizeIndex);
cacheTable->bins = Cal_MemAlloc(CacheEntry_t, cacheTable->numBins);
if(cacheTable->bins == Cal_Nil(CacheEntry_t)){
CalBddFatalMessage("out of memory");
}

memset((char *)cacheTable->bins, 0,
cacheTable->numBins*sizeof(CacheEntry_t));

for(i = 0; i < oldNumBins; i++){
bin = oldBins+i;
if (bin->opCode == CAL_OP_INVALID) continue;
hashValue = CacheTableTwoDoHash(cacheTable,
bin->operand1,
bin->operand2,
bin->opCode);
newBin = cacheTable->bins+hashValue;
if (newBin->opCode != CAL_OP_INVALID){
cacheTable->numEntries--;
}
newBin->opCode = bin->opCode;
newBin->operand1 = bin->operand1;
newBin->operand2 = bin->operand2;
newBin->resultBddId = bin->resultBddId;
newBin->resultBddNode = bin->resultBddNode;
}
Cal_MemFree(oldBins);
}

/**Function********************************************************************
Free a Cache table along with the associated storage.
Expand Down Expand Up @@ -456,56 +505,6 @@ CalCacheTableMemoryConsumption(CalCacheTable_t *cacheTable)
/* Definition of static functions */
/*---------------------------------------------------------------------------*/

/**Function********************************************************************
******************************************************************************/
static void
CacheTableTwoRehash(CalCacheTable_t *cacheTable,int grow)
{
CacheEntry_t *oldBins = cacheTable->bins;
int i, hashValue;
int oldNumBins = cacheTable->numBins;
CacheEntry_t *bin, *newBin;


if(grow){
cacheTable->sizeIndex++;
}
else{
if (cacheTable->sizeIndex <= CACHE_TABLE_DEFAULT_SIZE_INDEX){/* No need to Rehash */
return;
}
cacheTable->sizeIndex--;
}

cacheTable->numBins = TABLE_SIZE(cacheTable->sizeIndex);
cacheTable->bins = Cal_MemAlloc(CacheEntry_t, cacheTable->numBins);
if(cacheTable->bins == Cal_Nil(CacheEntry_t)){
CalBddFatalMessage("out of memory");
}

memset((char *)cacheTable->bins, 0,
cacheTable->numBins*sizeof(CacheEntry_t));

for(i = 0; i < oldNumBins; i++){
bin = oldBins+i;
if (bin->opCode == CAL_OP_INVALID) continue;
hashValue = CacheTableTwoDoHash(cacheTable,
bin->operand1,
bin->operand2,
bin->opCode);
newBin = cacheTable->bins+hashValue;
if (newBin->opCode != CAL_OP_INVALID){
cacheTable->numEntries--;
}
newBin->opCode = bin->opCode;
newBin->operand1 = bin->operand1;
newBin->operand2 = bin->operand2;
newBin->resultBddId = bin->resultBddId;
newBin->resultBddNode = bin->resultBddNode;
}
Cal_MemFree(oldBins);
}

/**Function********************************************************************
******************************************************************************/
static void
Expand Down
1 change: 1 addition & 0 deletions src/calInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ EXTERN Cal_Block CalBddShiftBlock(Cal_BddManager_t *bddManager, Cal_Block b, lon
EXTERN unsigned long CalBlockMemoryConsumption(Cal_Block block);
EXTERN void CalFreeBlockRecursively(Cal_Block block);
EXTERN CalCacheTable_t * CalCacheTableTwoInit(Cal_BddManager_t *bddManager);
EXTERN void CacheTableTwoRehash(CalCacheTable_t *cacheTable, int grow);
EXTERN int CalCacheTableTwoQuit(CalCacheTable_t *cacheTable);
EXTERN void CalCacheTableTwoInsert(Cal_BddManager_t *bddManager, Cal_Bdd_t f, Cal_Bdd_t g, Cal_Bdd_t result, unsigned long opCode, int cacheLevel);
EXTERN int CalCacheTableTwoLookup(Cal_BddManager_t *bddManager, Cal_Bdd_t f, Cal_Bdd_t g, unsigned long opCode, Cal_Bdd_t *resultBddPtr);
Expand Down

0 comments on commit 1eb854d

Please sign in to comment.