SVF
Macros | Functions | Variables
cuddLCache.c File Reference
#include "CUDD/util.h"
#include "CUDD/cuddInt.h"

Go to the source code of this file.

Macros

#define DD_MAX_HASHTABLE_DENSITY   2 /* tells when to resize a table */
 
#define ddLCHash1(f, shift)   (((unsigned)(f) * DD_P1) >> (shift))
 
#define ddLCHash2(f, g, shift)   ((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2) >> (shift))
 
#define ddLCHash3(f, g, h, shift)   ddCHash2(f,g,h,shift)
 

Functions

static void cuddLocalCacheResize (DdLocalCache *cache)
 
static DD_INLINE unsigned int ddLCHash (DdNodePtr *key, unsigned int keysize, int shift)
 
static void cuddLocalCacheAddToList (DdLocalCache *cache)
 
static void cuddLocalCacheRemoveFromList (DdLocalCache *cache)
 
static int cuddHashTableResize (DdHashTable *hash)
 
static DD_INLINE DdHashItemcuddHashTableAlloc (DdHashTable *hash)
 
DdLocalCachecuddLocalCacheInit (DdManager *manager, unsigned int keySize, unsigned int cacheSize, unsigned int maxCacheSize)
 
void cuddLocalCacheQuit (DdLocalCache *cache)
 
void cuddLocalCacheInsert (DdLocalCache *cache, DdNodePtr *key, DdNode *value)
 
DdNodecuddLocalCacheLookup (DdLocalCache *cache, DdNodePtr *key)
 
void cuddLocalCacheClearDead (DdManager *manager)
 
void cuddLocalCacheClearAll (DdManager *manager)
 
DdHashTablecuddHashTableInit (DdManager *manager, unsigned int keySize, unsigned int initSize)
 
void cuddHashTableQuit (DdHashTable *hash)
 
void cuddHashTableGenericQuit (DdHashTable *hash)
 
int cuddHashTableInsert (DdHashTable *hash, DdNodePtr *key, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup (DdHashTable *hash, DdNodePtr *key)
 
int cuddHashTableInsert1 (DdHashTable *hash, DdNode *f, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup1 (DdHashTable *hash, DdNode *f)
 
int cuddHashTableGenericInsert (DdHashTable *hash, DdNode *f, void *value)
 
void * cuddHashTableGenericLookup (DdHashTable *hash, DdNode *f)
 
int cuddHashTableInsert2 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup2 (DdHashTable *hash, DdNode *f, DdNode *g)
 
int cuddHashTableInsert3 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *h, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup3 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *h)
 

Variables

static char rcsid [] DD_UNUSED = "$Id: cuddLCache.c,v 1.27 2012/02/05 01:07:19 fabio Exp $"
 

Macro Definition Documentation

◆ DD_MAX_HASHTABLE_DENSITY

#define DD_MAX_HASHTABLE_DENSITY   2 /* tells when to resize a table */

CFile***********************************************************************

FileName [cuddLCache.c]

PackageName [cudd]

Synopsis [Functions for local caches.]

Description [Internal procedures included in this module:

Static procedures included in this module:

]

SeeAlso []

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 85 of file cuddLCache.c.

◆ ddLCHash1

#define ddLCHash1 (   f,
  shift 
)    (((unsigned)(f) * DD_P1) >> (shift))

Macro***********************************************************************

Synopsis [Computes hash function for keys of one operand.]

Description []

SideEffects [None]

SeeAlso [ddLCHash3 ddLCHash]

Definition at line 124 of file cuddLCache.c.

◆ ddLCHash2

#define ddLCHash2 (   f,
  g,
  shift 
)    ((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2) >> (shift))

Macro***********************************************************************

Synopsis [Computes hash function for keys of two operands.]

Description []

SideEffects [None]

SeeAlso [ddLCHash3 ddLCHash]

Definition at line 145 of file cuddLCache.c.

◆ ddLCHash3

#define ddLCHash3 (   f,
  g,
  h,
  shift 
)    ddCHash2(f,g,h,shift)

Macro***********************************************************************

Synopsis [Computes hash function for keys of three operands.]

Description []

SideEffects [None]

SeeAlso [ddLCHash2 ddLCHash]

Definition at line 161 of file cuddLCache.c.

Function Documentation

◆ cuddHashTableAlloc()

static DD_INLINE DdHashItem * cuddHashTableAlloc ( DdHashTable hash)
static

Function********************************************************************

Synopsis [Fast storage allocation for items in a hash table.]

Description [Fast storage allocation for items in a hash table. The first 4 bytes of a chunk contain a pointer to the next block; the rest contains DD_MEM_CHUNK spaces for hash items. Returns a pointer to a new item if successful; NULL is memory is full.]

SideEffects [None]

SeeAlso [cuddAllocNode cuddDynamicAllocNode]

Definition at line 1503 of file cuddLCache.c.

1505 {
1506  int i;
1507  unsigned int itemsize = hash->itemsize;
1508  extern DD_OOMFP MMoutOfMemory;
1509  DD_OOMFP saveHandler;
1510  DdHashItem **mem, *thisOne, *next, *item;
1511 
1512  if (hash->nextFree == NULL) {
1513  saveHandler = MMoutOfMemory;
1514  MMoutOfMemory = Cudd_OutOfMem;
1515  mem = (DdHashItem **) ALLOC(char,(DD_MEM_CHUNK+1) * itemsize);
1516  MMoutOfMemory = saveHandler;
1517  if (mem == NULL) {
1518  if (hash->manager->stash != NULL) {
1519  FREE(hash->manager->stash);
1520  hash->manager->stash = NULL;
1521  /* Inhibit resizing of tables. */
1522  hash->manager->maxCacheHard = hash->manager->cacheSlots - 1;
1523  hash->manager->cacheSlack = - (int) (hash->manager->cacheSlots + 1);
1524  for (i = 0; i < hash->manager->size; i++) {
1525  hash->manager->subtables[i].maxKeys <<= 2;
1526  }
1527  hash->manager->gcFrac = 0.2;
1528  hash->manager->minDead =
1529  (unsigned) (0.2 * (double) hash->manager->slots);
1530  mem = (DdHashItem **) ALLOC(char,(DD_MEM_CHUNK+1) * itemsize);
1531  }
1532  if (mem == NULL) {
1533  (*MMoutOfMemory)((long)((DD_MEM_CHUNK + 1) * itemsize));
1535  return(NULL);
1536  }
1537  }
1538 
1539  mem[0] = (DdHashItem *) hash->memoryList;
1540  hash->memoryList = mem;
1541 
1542  thisOne = (DdHashItem *) ((char *) mem + itemsize);
1543  hash->nextFree = thisOne;
1544  for (i = 1; i < DD_MEM_CHUNK; i++) {
1545  next = (DdHashItem *) ((char *) thisOne + itemsize);
1546  thisOne->next = next;
1547  thisOne = next;
1548  }
1549 
1550  thisOne->next = NULL;
1551 
1552  }
1553  item = hash->nextFree;
1554  hash->nextFree = item->next;
1555  return(item);
1556 
1557 } /* end of cuddHashTableAlloc */
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2845
#define FREE(obj)
Definition: util.h:80
DdManager * manager
Definition: cuddInt.h:298
int size
Definition: cuddInt.h:345
double gcFrac
Definition: cuddInt.h:359
unsigned int maxCacheHard
Definition: cuddInt.h:343
unsigned int slots
Definition: cuddInt.h:352
struct DdHashItem * next
Definition: cuddInt.h:281
DdSubtable * subtables
Definition: cuddInt.h:349
void(* DD_OOMFP)(long)
Definition: cudd.h:311
unsigned int cacheSlots
Definition: cuddInt.h:337
char * stash
Definition: cuddInt.h:382
#define ALLOC(type, num)
Definition: util.h:76
unsigned int maxKeys
Definition: cuddInt.h:315
int cacheSlack
Definition: cuddInt.h:342
void(* MMoutOfMemory)(long)
Definition: safe_mem.c:32
unsigned int itemsize
Definition: cuddInt.h:290
DdHashItem * nextFree
Definition: cuddInt.h:292
#define DD_MEM_CHUNK
Definition: cuddInt.h:105
DdHashItem ** memoryList
Definition: cuddInt.h:293
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
unsigned int minDead
Definition: cuddInt.h:358

◆ cuddHashTableGenericInsert()

int cuddHashTableGenericInsert ( DdHashTable hash,
DdNode f,
void *  value 
)

Function********************************************************************

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is one pointer and the value is not a DdNode pointer. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert1 cuddHashTableGenericLookup]

Definition at line 919 of file cuddLCache.c.

923 {
924  int result;
925  unsigned int posn;
926  DdHashItem *item;
927 
928 #ifdef DD_DEBUG
929  assert(hash->keysize == 1);
930 #endif
931 
932  if (hash->size > hash->maxsize) {
933  result = cuddHashTableResize(hash);
934  if (result == 0) return(0);
935  }
936  item = cuddHashTableAlloc(hash);
937  if (item == NULL) return(0);
938  hash->size++;
939  item->value = (DdNode *) value;
940  item->count = 0;
941  item->key[0] = f;
942  posn = ddLCHash1(f,hash->shift);
943  item->next = hash->bucket[posn];
944  hash->bucket[posn] = item;
945 
946  return(1);
947 
948 } /* end of cuddHashTableGenericInsert */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
Definition: cudd.h:270
#define assert(ex)
Definition: util.h:141
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1503
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
#define ddLCHash1(f, shift)
Definition: cuddLCache.c:124
unsigned int maxsize
Definition: cuddInt.h:297
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295
static int result
Definition: cuddGenetic.c:121
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1401

◆ cuddHashTableGenericLookup()

void* cuddHashTableGenericLookup ( DdHashTable hash,
DdNode f 
)

Function********************************************************************

Synopsis [Looks up a key consisting of one pointer in a hash table.]

Description [Looks up a key consisting of one pointer in a hash table when the value is not a DdNode pointer. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableLookup1 cuddHashTableGenericInsert]

Definition at line 966 of file cuddLCache.c.

969 {
970  unsigned int posn;
971  DdHashItem *item;
972 
973 #ifdef DD_DEBUG
974  assert(hash->keysize == 1);
975 #endif
976 
977  posn = ddLCHash1(f,hash->shift);
978  item = hash->bucket[posn];
979 
980  while (item != NULL) {
981  if (f == item->key[0]) {
982  return ((void *) item->value);
983  }
984  item = item->next;
985  }
986  return(NULL);
987 
988 } /* end of cuddHashTableGenericLookup */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
#define assert(ex)
Definition: util.h:141
struct DdHashItem * next
Definition: cuddInt.h:281
#define ddLCHash1(f, shift)
Definition: cuddLCache.c:124
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295

◆ cuddHashTableGenericQuit()

void cuddHashTableGenericQuit ( DdHashTable hash)

Function********************************************************************

Synopsis [Shuts down a hash table.]

Description [Shuts down a hash table, when the values are not DdNode pointers.]

SideEffects [None]

SeeAlso [cuddHashTableInit]

Definition at line 652 of file cuddLCache.c.

654 {
655 #ifdef __osf__
656 #pragma pointer_size save
657 #pragma pointer_size short
658 #endif
659  DdHashItem **memlist, **nextmem;
660 
661  memlist = hash->memoryList;
662  while (memlist != NULL) {
663  nextmem = (DdHashItem **) memlist[0];
664  FREE(memlist);
665  memlist = nextmem;
666  }
667 
668  FREE(hash->bucket);
669  FREE(hash);
670 #ifdef __osf__
671 #pragma pointer_size restore
672 #endif
673 
674  return;
675 
676 } /* end of cuddHashTableGenericQuit */
DdHashItem ** bucket
Definition: cuddInt.h:291
#define FREE(obj)
Definition: util.h:80
DdHashItem ** memoryList
Definition: cuddInt.h:293

◆ cuddHashTableInit()

DdHashTable* cuddHashTableInit ( DdManager manager,
unsigned int  keySize,
unsigned int  initSize 
)

Function********************************************************************

Synopsis [Initializes a hash table.]

Description [Initializes a hash table. Returns a pointer to the new table if successful; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableQuit]

Definition at line 557 of file cuddLCache.c.

561 {
562  DdHashTable *hash;
563  int logSize;
564 
565  hash = ALLOC(DdHashTable, 1);
566  if (hash == NULL) {
567  manager->errorCode = CUDD_MEMORY_OUT;
568  return(NULL);
569  }
570  hash->keysize = keySize;
571  hash->manager = manager;
572  hash->memoryList = NULL;
573  hash->nextFree = NULL;
574  hash->itemsize = (keySize + 1) * sizeof(DdNode *) +
575  sizeof(ptrint) + sizeof(DdHashItem *);
576  /* We have to guarantee that the shift be < 32. */
577  if (initSize < 2) initSize = 2;
578  logSize = cuddComputeFloorLog2(initSize);
579  hash->numBuckets = 1 << logSize;
580  hash->shift = sizeof(int) * 8 - logSize;
581  hash->bucket = ALLOC(DdHashItem *, hash->numBuckets);
582  if (hash->bucket == NULL) {
583  manager->errorCode = CUDD_MEMORY_OUT;
584  FREE(hash);
585  return(NULL);
586  }
587  memset(hash->bucket, 0, hash->numBuckets * sizeof(DdHashItem *));
588  hash->size = 0;
590  return(hash);
591 
592 } /* end of cuddHashTableInit */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
int ptrint
Definition: cuddInt.h:249
unsigned int size
Definition: cuddInt.h:296
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
DdManager * manager
Definition: cuddInt.h:298
char * memset()
#define ALLOC(type, num)
Definition: util.h:76
unsigned int numBuckets
Definition: cuddInt.h:294
unsigned int maxsize
Definition: cuddInt.h:297
unsigned int itemsize
Definition: cuddInt.h:290
DdHashItem * nextFree
Definition: cuddInt.h:292
int shift
Definition: cuddInt.h:295
int cuddComputeFloorLog2(unsigned int value)
Definition: cuddCache.c:1036
DdHashItem ** memoryList
Definition: cuddInt.h:293
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
#define DD_MAX_HASHTABLE_DENSITY
Definition: cuddLCache.c:85

◆ cuddHashTableInsert()

int cuddHashTableInsert ( DdHashTable hash,
DdNodePtr key,
DdNode value,
ptrint  count 
)

Function********************************************************************

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key has more than three pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [[cuddHashTableInsert1 cuddHashTableInsert2 cuddHashTableInsert3 cuddHashTableLookup]

Definition at line 693 of file cuddLCache.c.

698 {
699  int result;
700  unsigned int posn;
701  DdHashItem *item;
702  unsigned int i;
703 
704 #ifdef DD_DEBUG
705  assert(hash->keysize > 3);
706 #endif
707 
708  if (hash->size > hash->maxsize) {
709  result = cuddHashTableResize(hash);
710  if (result == 0) return(0);
711  }
712  item = cuddHashTableAlloc(hash);
713  if (item == NULL) return(0);
714  hash->size++;
715  item->value = value;
716  cuddRef(value);
717  item->count = count;
718  for (i = 0; i < hash->keysize; i++) {
719  item->key[i] = key[i];
720  }
721  posn = ddLCHash(key,hash->keysize,hash->shift);
722  item->next = hash->bucket[posn];
723  hash->bucket[posn] = item;
724 
725  return(1);
726 
727 } /* end of cuddHashTableInsert */
unsigned int keysize
Definition: cuddInt.h:289
#define cuddRef(n)
Definition: cuddInt.h:557
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define assert(ex)
Definition: util.h:141
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1503
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
unsigned int maxsize
Definition: cuddInt.h:297
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295
static int result
Definition: cuddGenetic.c:121
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1401

◆ cuddHashTableInsert1()

int cuddHashTableInsert1 ( DdHashTable hash,
DdNode f,
DdNode value,
ptrint  count 
)

Function********************************************************************

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is one pointer. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert2 cuddHashTableInsert3 cuddHashTableLookup1]

Definition at line 812 of file cuddLCache.c.

817 {
818  int result;
819  unsigned int posn;
820  DdHashItem *item;
821 
822 #ifdef DD_DEBUG
823  assert(hash->keysize == 1);
824 #endif
825 
826  if (hash->size > hash->maxsize) {
827  result = cuddHashTableResize(hash);
828  if (result == 0) return(0);
829  }
830  item = cuddHashTableAlloc(hash);
831  if (item == NULL) return(0);
832  hash->size++;
833  item->value = value;
834  cuddRef(value);
835  item->count = count;
836  item->key[0] = f;
837  posn = ddLCHash1(f,hash->shift);
838  item->next = hash->bucket[posn];
839  hash->bucket[posn] = item;
840 
841  return(1);
842 
843 } /* end of cuddHashTableInsert1 */
unsigned int keysize
Definition: cuddInt.h:289
#define cuddRef(n)
Definition: cuddInt.h:557
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define assert(ex)
Definition: util.h:141
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1503
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
#define ddLCHash1(f, shift)
Definition: cuddLCache.c:124
unsigned int maxsize
Definition: cuddInt.h:297
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295
static int result
Definition: cuddGenetic.c:121
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1401

◆ cuddHashTableInsert2()

int cuddHashTableInsert2 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode value,
ptrint  count 
)

Function********************************************************************

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is composed of two pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert1 cuddHashTableInsert3 cuddHashTableLookup2]

Definition at line 1005 of file cuddLCache.c.

1011 {
1012  int result;
1013  unsigned int posn;
1014  DdHashItem *item;
1015 
1016 #ifdef DD_DEBUG
1017  assert(hash->keysize == 2);
1018 #endif
1019 
1020  if (hash->size > hash->maxsize) {
1021  result = cuddHashTableResize(hash);
1022  if (result == 0) return(0);
1023  }
1024  item = cuddHashTableAlloc(hash);
1025  if (item == NULL) return(0);
1026  hash->size++;
1027  item->value = value;
1028  cuddRef(value);
1029  item->count = count;
1030  item->key[0] = f;
1031  item->key[1] = g;
1032  posn = ddLCHash2(f,g,hash->shift);
1033  item->next = hash->bucket[posn];
1034  hash->bucket[posn] = item;
1035 
1036  return(1);
1037 
1038 } /* end of cuddHashTableInsert2 */
unsigned int keysize
Definition: cuddInt.h:289
#define cuddRef(n)
Definition: cuddInt.h:557
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define assert(ex)
Definition: util.h:141
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1503
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
unsigned int maxsize
Definition: cuddInt.h:297
DdNode * key[1]
Definition: cuddInt.h:284
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:145
int shift
Definition: cuddInt.h:295
static int result
Definition: cuddGenetic.c:121
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1401

◆ cuddHashTableInsert3()

int cuddHashTableInsert3 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode h,
DdNode value,
ptrint  count 
)

Function********************************************************************

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is composed of three pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert1 cuddHashTableInsert2 cuddHashTableLookup3]

Definition at line 1115 of file cuddLCache.c.

1122 {
1123  int result;
1124  unsigned int posn;
1125  DdHashItem *item;
1126 
1127 #ifdef DD_DEBUG
1128  assert(hash->keysize == 3);
1129 #endif
1130 
1131  if (hash->size > hash->maxsize) {
1132  result = cuddHashTableResize(hash);
1133  if (result == 0) return(0);
1134  }
1135  item = cuddHashTableAlloc(hash);
1136  if (item == NULL) return(0);
1137  hash->size++;
1138  item->value = value;
1139  cuddRef(value);
1140  item->count = count;
1141  item->key[0] = f;
1142  item->key[1] = g;
1143  item->key[2] = h;
1144  posn = ddLCHash3(f,g,h,hash->shift);
1145  item->next = hash->bucket[posn];
1146  hash->bucket[posn] = item;
1147 
1148  return(1);
1149 
1150 } /* end of cuddHashTableInsert3 */
unsigned int keysize
Definition: cuddInt.h:289
#define cuddRef(n)
Definition: cuddInt.h:557
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define assert(ex)
Definition: util.h:141
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1503
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
unsigned int maxsize
Definition: cuddInt.h:297
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295
static int result
Definition: cuddGenetic.c:121
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:161
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1401

◆ cuddHashTableLookup()

DdNode* cuddHashTableLookup ( DdHashTable hash,
DdNodePtr key 
)

Function********************************************************************

Synopsis [Looks up a key in a hash table.]

Description [Looks up a key consisting of more than three pointers in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup1 cuddHashTableLookup2 cuddHashTableLookup3 cuddHashTableInsert]

Definition at line 748 of file cuddLCache.c.

751 {
752  unsigned int posn;
753  DdHashItem *item, *prev;
754  unsigned int i, keysize;
755 
756 #ifdef DD_DEBUG
757  assert(hash->keysize > 3);
758 #endif
759 
760  posn = ddLCHash(key,hash->keysize,hash->shift);
761  item = hash->bucket[posn];
762  prev = NULL;
763 
764  keysize = hash->keysize;
765  while (item != NULL) {
766  DdNodePtr *key2 = item->key;
767  int equal = 1;
768  for (i = 0; i < keysize; i++) {
769  if (key[i] != key2[i]) {
770  equal = 0;
771  break;
772  }
773  }
774  if (equal) {
775  DdNode *value = item->value;
776  cuddSatDec(item->count);
777  if (item->count == 0) {
778  cuddDeref(value);
779  if (prev == NULL) {
780  hash->bucket[posn] = item->next;
781  } else {
782  prev->next = item->next;
783  }
784  item->next = hash->nextFree;
785  hash->nextFree = item;
786  hash->size--;
787  }
788  return(value);
789  }
790  prev = item;
791  item = item->next;
792  }
793  return(NULL);
794 
795 } /* end of cuddHashTableLookup */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define cuddDeref(n)
Definition: cuddInt.h:577
Definition: cudd.h:270
#define assert(ex)
Definition: util.h:141
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
DdHashItem * nextFree
Definition: cuddInt.h:292
#define cuddSatDec(x)
Definition: cuddInt.h:849
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295

◆ cuddHashTableLookup1()

DdNode* cuddHashTableLookup1 ( DdHashTable hash,
DdNode f 
)

Function********************************************************************

Synopsis [Looks up a key consisting of one pointer in a hash table.]

Description [Looks up a key consisting of one pointer in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup2 cuddHashTableLookup3 cuddHashTableInsert1]

Definition at line 864 of file cuddLCache.c.

867 {
868  unsigned int posn;
869  DdHashItem *item, *prev;
870 
871 #ifdef DD_DEBUG
872  assert(hash->keysize == 1);
873 #endif
874 
875  posn = ddLCHash1(f,hash->shift);
876  item = hash->bucket[posn];
877  prev = NULL;
878 
879  while (item != NULL) {
880  DdNodePtr *key = item->key;
881  if (f == key[0]) {
882  DdNode *value = item->value;
883  cuddSatDec(item->count);
884  if (item->count == 0) {
885  cuddDeref(value);
886  if (prev == NULL) {
887  hash->bucket[posn] = item->next;
888  } else {
889  prev->next = item->next;
890  }
891  item->next = hash->nextFree;
892  hash->nextFree = item;
893  hash->size--;
894  }
895  return(value);
896  }
897  prev = item;
898  item = item->next;
899  }
900  return(NULL);
901 
902 } /* end of cuddHashTableLookup1 */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define cuddDeref(n)
Definition: cuddInt.h:577
Definition: cudd.h:270
#define assert(ex)
Definition: util.h:141
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
#define ddLCHash1(f, shift)
Definition: cuddLCache.c:124
DdHashItem * nextFree
Definition: cuddInt.h:292
#define cuddSatDec(x)
Definition: cuddInt.h:849
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295

◆ cuddHashTableLookup2()

DdNode* cuddHashTableLookup2 ( DdHashTable hash,
DdNode f,
DdNode g 
)

Function********************************************************************

Synopsis [Looks up a key consisting of two pointers in a hash table.]

Description [Looks up a key consisting of two pointer in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup1 cuddHashTableLookup3 cuddHashTableInsert2]

Definition at line 1059 of file cuddLCache.c.

1063 {
1064  unsigned int posn;
1065  DdHashItem *item, *prev;
1066 
1067 #ifdef DD_DEBUG
1068  assert(hash->keysize == 2);
1069 #endif
1070 
1071  posn = ddLCHash2(f,g,hash->shift);
1072  item = hash->bucket[posn];
1073  prev = NULL;
1074 
1075  while (item != NULL) {
1076  DdNodePtr *key = item->key;
1077  if ((f == key[0]) && (g == key[1])) {
1078  DdNode *value = item->value;
1079  cuddSatDec(item->count);
1080  if (item->count == 0) {
1081  cuddDeref(value);
1082  if (prev == NULL) {
1083  hash->bucket[posn] = item->next;
1084  } else {
1085  prev->next = item->next;
1086  }
1087  item->next = hash->nextFree;
1088  hash->nextFree = item;
1089  hash->size--;
1090  }
1091  return(value);
1092  }
1093  prev = item;
1094  item = item->next;
1095  }
1096  return(NULL);
1097 
1098 } /* end of cuddHashTableLookup2 */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define cuddDeref(n)
Definition: cuddInt.h:577
Definition: cudd.h:270
#define assert(ex)
Definition: util.h:141
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
DdHashItem * nextFree
Definition: cuddInt.h:292
#define cuddSatDec(x)
Definition: cuddInt.h:849
DdNode * key[1]
Definition: cuddInt.h:284
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:145
int shift
Definition: cuddInt.h:295

◆ cuddHashTableLookup3()

DdNode* cuddHashTableLookup3 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode h 
)

Function********************************************************************

Synopsis [Looks up a key consisting of three pointers in a hash table.]

Description [Looks up a key consisting of three pointers in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup1 cuddHashTableLookup2 cuddHashTableInsert3]

Definition at line 1171 of file cuddLCache.c.

1176 {
1177  unsigned int posn;
1178  DdHashItem *item, *prev;
1179 
1180 #ifdef DD_DEBUG
1181  assert(hash->keysize == 3);
1182 #endif
1183 
1184  posn = ddLCHash3(f,g,h,hash->shift);
1185  item = hash->bucket[posn];
1186  prev = NULL;
1187 
1188  while (item != NULL) {
1189  DdNodePtr *key = item->key;
1190  if ((f == key[0]) && (g == key[1]) && (h == key[2])) {
1191  DdNode *value = item->value;
1192  cuddSatDec(item->count);
1193  if (item->count == 0) {
1194  cuddDeref(value);
1195  if (prev == NULL) {
1196  hash->bucket[posn] = item->next;
1197  } else {
1198  prev->next = item->next;
1199  }
1200  item->next = hash->nextFree;
1201  hash->nextFree = item;
1202  hash->size--;
1203  }
1204  return(value);
1205  }
1206  prev = item;
1207  item = item->next;
1208  }
1209  return(NULL);
1210 
1211 } /* end of cuddHashTableLookup3 */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
unsigned int size
Definition: cuddInt.h:296
#define cuddDeref(n)
Definition: cuddInt.h:577
Definition: cudd.h:270
#define assert(ex)
Definition: util.h:141
ptrint count
Definition: cuddInt.h:282
struct DdHashItem * next
Definition: cuddInt.h:281
DdHashItem * nextFree
Definition: cuddInt.h:292
#define cuddSatDec(x)
Definition: cuddInt.h:849
DdNode * key[1]
Definition: cuddInt.h:284
int shift
Definition: cuddInt.h:295
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:161

◆ cuddHashTableQuit()

void cuddHashTableQuit ( DdHashTable hash)

Function********************************************************************

Synopsis [Shuts down a hash table.]

Description [Shuts down a hash table, dereferencing all the values.]

SideEffects [None]

SeeAlso [cuddHashTableInit]

Definition at line 607 of file cuddLCache.c.

609 {
610  unsigned int i;
611  DdManager *dd = hash->manager;
612  DdHashItem *bucket;
613  DdHashItem **memlist, **nextmem;
614  unsigned int numBuckets = hash->numBuckets;
615 
616  for (i = 0; i < numBuckets; i++) {
617  bucket = hash->bucket[i];
618  while (bucket != NULL) {
619  Cudd_RecursiveDeref(dd, bucket->value);
620  bucket = bucket->next;
621  }
622  }
623 
624  memlist = hash->memoryList;
625  while (memlist != NULL) {
626  nextmem = (DdHashItem **) memlist[0];
627  FREE(memlist);
628  memlist = nextmem;
629  }
630 
631  FREE(hash->bucket);
632  FREE(hash);
633 
634  return;
635 
636 } /* end of cuddHashTableQuit */
DdHashItem ** bucket
Definition: cuddInt.h:291
DdNode * value
Definition: cuddInt.h:283
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:150
#define FREE(obj)
Definition: util.h:80
DdManager * manager
Definition: cuddInt.h:298
struct DdHashItem * next
Definition: cuddInt.h:281
unsigned int numBuckets
Definition: cuddInt.h:294
DdHashItem ** memoryList
Definition: cuddInt.h:293

◆ cuddHashTableResize()

static int cuddHashTableResize ( DdHashTable hash)
static

Function********************************************************************

Synopsis [Resizes a hash table.]

Description [Resizes a hash table. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert]

Definition at line 1401 of file cuddLCache.c.

1403 {
1404  int j;
1405  unsigned int posn;
1406  DdHashItem *item;
1407  DdHashItem *next;
1408  DdNode **key;
1409  int numBuckets;
1410  DdHashItem **buckets;
1411  DdHashItem **oldBuckets = hash->bucket;
1412  int shift;
1413  int oldNumBuckets = hash->numBuckets;
1414  extern DD_OOMFP MMoutOfMemory;
1415  DD_OOMFP saveHandler;
1416 
1417  /* Compute the new size of the table. */
1418  numBuckets = oldNumBuckets << 1;
1419  saveHandler = MMoutOfMemory;
1420  MMoutOfMemory = Cudd_OutOfMem;
1421  buckets = ALLOC(DdHashItem *, numBuckets);
1422  MMoutOfMemory = saveHandler;
1423  if (buckets == NULL) {
1424  hash->maxsize <<= 1;
1425  return(1);
1426  }
1427 
1428  hash->bucket = buckets;
1429  hash->numBuckets = numBuckets;
1430  shift = --(hash->shift);
1431  hash->maxsize <<= 1;
1432  memset(buckets, 0, numBuckets * sizeof(DdHashItem *));
1433  if (hash->keysize == 1) {
1434  for (j = 0; j < oldNumBuckets; j++) {
1435  item = oldBuckets[j];
1436  while (item != NULL) {
1437  next = item->next;
1438  key = item->key;
1439  posn = ddLCHash2(key[0], key[0], shift);
1440  item->next = buckets[posn];
1441  buckets[posn] = item;
1442  item = next;
1443  }
1444  }
1445  } else if (hash->keysize == 2) {
1446  for (j = 0; j < oldNumBuckets; j++) {
1447  item = oldBuckets[j];
1448  while (item != NULL) {
1449  next = item->next;
1450  key = item->key;
1451  posn = ddLCHash2(key[0], key[1], shift);
1452  item->next = buckets[posn];
1453  buckets[posn] = item;
1454  item = next;
1455  }
1456  }
1457  } else if (hash->keysize == 3) {
1458  for (j = 0; j < oldNumBuckets; j++) {
1459  item = oldBuckets[j];
1460  while (item != NULL) {
1461  next = item->next;
1462  key = item->key;
1463  posn = ddLCHash3(key[0], key[1], key[2], shift);
1464  item->next = buckets[posn];
1465  buckets[posn] = item;
1466  item = next;
1467  }
1468  }
1469  } else {
1470  for (j = 0; j < oldNumBuckets; j++) {
1471  item = oldBuckets[j];
1472  while (item != NULL) {
1473  next = item->next;
1474  posn = ddLCHash(item->key, hash->keysize, shift);
1475  item->next = buckets[posn];
1476  buckets[posn] = item;
1477  item = next;
1478  }
1479  }
1480  }
1481  FREE(oldBuckets);
1482  return(1);
1483 
1484 } /* end of cuddHashTableResize */
unsigned int keysize
Definition: cuddInt.h:289
DdHashItem ** bucket
Definition: cuddInt.h:291
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2845
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
struct DdHashItem * next
Definition: cuddInt.h:281
void(* DD_OOMFP)(long)
Definition: cudd.h:311
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
char * memset()
#define ALLOC(type, num)
Definition: util.h:76
unsigned int numBuckets
Definition: cuddInt.h:294
unsigned int maxsize
Definition: cuddInt.h:297
void(* MMoutOfMemory)(long)
Definition: safe_mem.c:32
DdNode * key[1]
Definition: cuddInt.h:284
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:145
int shift
Definition: cuddInt.h:295
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:161

◆ cuddLocalCacheAddToList()

static void cuddLocalCacheAddToList ( DdLocalCache cache)
static

Function********************************************************************

Synopsis [Inserts a local cache in the manager list.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1342 of file cuddLCache.c.

1344 {
1345  DdManager *manager = cache->manager;
1346 
1347  cache->next = manager->localCaches;
1348  manager->localCaches = cache;
1349  return;
1350 
1351 } /* end of cuddLocalCacheAddToList */
struct DdLocalCache * next
Definition: cuddInt.h:276
DdLocalCache * localCaches
Definition: cuddInt.h:417
DdManager * manager
Definition: cuddInt.h:275

◆ cuddLocalCacheClearAll()

void cuddLocalCacheClearAll ( DdManager manager)

Function********************************************************************

Synopsis [Clears the local caches of a manager.]

Description [Clears the local caches of a manager. Used before reordering.]

SideEffects [None]

SeeAlso []

Definition at line 423 of file cuddLCache.c.

425 {
426  DdLocalCache *cache = manager->localCaches;
427 
428  while (cache != NULL) {
429  memset(cache->item, 0, cache->slots * cache->itemsize);
430  cache = cache->next;
431  }
432  return;
433 
434 } /* end of cuddLocalCacheClearAll */
DdLocalCacheItem * item
Definition: cuddInt.h:266
struct DdLocalCache * next
Definition: cuddInt.h:276
char * memset()
unsigned int itemsize
Definition: cuddInt.h:267
unsigned int slots
Definition: cuddInt.h:269
DdLocalCache * localCaches
Definition: cuddInt.h:417

◆ cuddLocalCacheClearDead()

void cuddLocalCacheClearDead ( DdManager manager)

Function********************************************************************

Synopsis [Clears the dead entries of the local caches of a manager.]

Description [Clears the dead entries of the local caches of a manager. Used during garbage collection.]

SideEffects [None]

SeeAlso []

Definition at line 371 of file cuddLCache.c.

373 {
374  DdLocalCache *cache = manager->localCaches;
375  unsigned int keysize;
376  unsigned int itemsize;
377  unsigned int slots;
378  DdLocalCacheItem *item;
379  DdNodePtr *key;
380  unsigned int i, j;
381 
382  while (cache != NULL) {
383  keysize = cache->keysize;
384  itemsize = cache->itemsize;
385  slots = cache->slots;
386  item = cache->item;
387  for (i = 0; i < slots; i++) {
388  if (item->value != NULL) {
389  if (Cudd_Regular(item->value)->ref == 0) {
390  item->value = NULL;
391  } else {
392  key = item->key;
393  for (j = 0; j < keysize; j++) {
394  if (Cudd_Regular(key[j])->ref == 0) {
395  item->value = NULL;
396  break;
397  }
398  }
399  }
400  }
401  item = (DdLocalCacheItem *) ((char *) item + itemsize);
402  }
403  cache = cache->next;
404  }
405  return;
406 
407 } /* end of cuddLocalCacheClearDead */
Definition: cudd.h:270
#define Cudd_Regular(node)
Definition: cudd.h:384
DdNode * value
Definition: cuddInt.h:257
unsigned int keysize
Definition: cuddInt.h:268
DdLocalCacheItem * item
Definition: cuddInt.h:266
struct DdLocalCache * next
Definition: cuddInt.h:276
unsigned int itemsize
Definition: cuddInt.h:267
unsigned int slots
Definition: cuddInt.h:269
DdLocalCache * localCaches
Definition: cuddInt.h:417
DdNode * key[1]
Definition: cuddInt.h:261

◆ cuddLocalCacheInit()

DdLocalCache* cuddLocalCacheInit ( DdManager manager,
unsigned int  keySize,
unsigned int  cacheSize,
unsigned int  maxCacheSize 
)

AutomaticEnd Function********************************************************************

Synopsis [Initializes a local computed table.]

Description [Initializes a computed table. Returns a pointer the the new local cache in case of success; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddInitCache]

Definition at line 202 of file cuddLCache.c.

207 {
208  DdLocalCache *cache;
209  int logSize;
210 
211  cache = ALLOC(DdLocalCache,1);
212  if (cache == NULL) {
213  manager->errorCode = CUDD_MEMORY_OUT;
214  return(NULL);
215  }
216  cache->manager = manager;
217  cache->keysize = keySize;
218  cache->itemsize = (keySize + 1) * sizeof(DdNode *);
219 #ifdef DD_CACHE_PROFILE
220  cache->itemsize += sizeof(ptrint);
221 #endif
222  logSize = cuddComputeFloorLog2(ddMax(cacheSize,manager->slots/2));
223  cacheSize = 1 << logSize;
224  cache->item = (DdLocalCacheItem *)
225  ALLOC(char, cacheSize * cache->itemsize);
226  if (cache->item == NULL) {
227  manager->errorCode = CUDD_MEMORY_OUT;
228  FREE(cache);
229  return(NULL);
230  }
231  cache->slots = cacheSize;
232  cache->shift = sizeof(int) * 8 - logSize;
233  cache->maxslots = ddMin(maxCacheSize,manager->slots);
234  cache->minHit = manager->minHit;
235  /* Initialize to avoid division by 0 and immediate resizing. */
236  cache->lookUps = (double) (int) (cacheSize * cache->minHit + 1);
237  cache->hits = 0;
238  manager->memused += cacheSize * cache->itemsize + sizeof(DdLocalCache);
239 
240  /* Initialize the cache. */
241  memset(cache->item, 0, cacheSize * cache->itemsize);
242 
243  /* Add to manager's list of local caches for GC. */
245 
246  return(cache);
247 
248 } /* end of cuddLocalCacheInit */
int ptrint
Definition: cuddInt.h:249
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
unsigned int slots
Definition: cuddInt.h:352
double minHit
Definition: cuddInt.h:272
unsigned int keysize
Definition: cuddInt.h:268
DdLocalCacheItem * item
Definition: cuddInt.h:266
unsigned int maxslots
Definition: cuddInt.h:274
char * memset()
unsigned int itemsize
Definition: cuddInt.h:267
#define ALLOC(type, num)
Definition: util.h:76
double hits
Definition: cuddInt.h:273
double lookUps
Definition: cuddInt.h:271
unsigned int slots
Definition: cuddInt.h:269
#define ddMax(x, y)
Definition: cuddInt.h:785
#define ddMin(x, y)
Definition: cuddInt.h:771
unsigned long memused
Definition: cuddInt.h:429
double minHit
Definition: cuddInt.h:341
struct DdLocalCache DdLocalCache
int cuddComputeFloorLog2(unsigned int value)
Definition: cuddCache.c:1036
DdManager * manager
Definition: cuddInt.h:275
static void cuddLocalCacheAddToList(DdLocalCache *cache)
Definition: cuddLCache.c:1342
Cudd_ErrorType errorCode
Definition: cuddInt.h:425

◆ cuddLocalCacheInsert()

void cuddLocalCacheInsert ( DdLocalCache cache,
DdNodePtr key,
DdNode value 
)

Function********************************************************************

Synopsis [Inserts a result in a local cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 291 of file cuddLCache.c.

295 {
296  unsigned int posn;
298 
299  posn = ddLCHash(key,cache->keysize,cache->shift);
300  entry = (DdLocalCacheItem *) ((char *) cache->item +
301  posn * cache->itemsize);
302  memcpy(entry->key,key,cache->keysize * sizeof(DdNode *));
303  entry->value = value;
304 #ifdef DD_CACHE_PROFILE
305  entry->count++;
306 #endif
307 
308 } /* end of cuddLocalCacheInsert */
Definition: cudd.h:270
char * memcpy()
DdNode * value
Definition: cuddInt.h:257
unsigned int keysize
Definition: cuddInt.h:268
DdLocalCacheItem * item
Definition: cuddInt.h:266
static int * entry
Definition: cuddGroup.c:119
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
unsigned int itemsize
Definition: cuddInt.h:267
DdNode * key[1]
Definition: cuddInt.h:261

◆ cuddLocalCacheLookup()

DdNode* cuddLocalCacheLookup ( DdLocalCache cache,
DdNodePtr key 
)

Function********************************************************************

Synopsis [Looks up in a local cache.]

Description [Looks up in a local cache. Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso []

Definition at line 324 of file cuddLCache.c.

327 {
328  unsigned int posn;
330  DdNode *value;
331 
332  cache->lookUps++;
333  posn = ddLCHash(key,cache->keysize,cache->shift);
334  entry = (DdLocalCacheItem *) ((char *) cache->item +
335  posn * cache->itemsize);
336  if (entry->value != NULL &&
337  memcmp(key,entry->key,cache->keysize*sizeof(DdNode *)) == 0) {
338  cache->hits++;
339  value = Cudd_Regular(entry->value);
340  if (value->ref == 0) {
341  cuddReclaim(cache->manager,value);
342  }
343  return(entry->value);
344  }
345 
346  /* Cache miss: decide whether to resize */
347 
348  if (cache->slots < cache->maxslots &&
349  cache->hits > cache->lookUps * cache->minHit) {
350  cuddLocalCacheResize(cache);
351  }
352 
353  return(NULL);
354 
355 } /* end of cuddLocalCacheLookup */
DdHalfWord ref
Definition: cudd.h:272
Definition: cudd.h:270
#define Cudd_Regular(node)
Definition: cudd.h:384
void cuddReclaim(DdManager *table, DdNode *n)
Definition: cuddRef.c:580
DdNode * value
Definition: cuddInt.h:257
double minHit
Definition: cuddInt.h:272
unsigned int keysize
Definition: cuddInt.h:268
DdLocalCacheItem * item
Definition: cuddInt.h:266
static int * entry
Definition: cuddGroup.c:119
unsigned int maxslots
Definition: cuddInt.h:274
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
unsigned int itemsize
Definition: cuddInt.h:267
double hits
Definition: cuddInt.h:273
double lookUps
Definition: cuddInt.h:271
unsigned int slots
Definition: cuddInt.h:269
static void cuddLocalCacheResize(DdLocalCache *cache)
Definition: cuddLCache.c:1231
int memcmp()
DdNode * key[1]
Definition: cuddInt.h:261
DdManager * manager
Definition: cuddInt.h:275

◆ cuddLocalCacheQuit()

void cuddLocalCacheQuit ( DdLocalCache cache)

Function********************************************************************

Synopsis [Shuts down a local computed table.]

Description [Initializes the computed table. It is called by Cudd_Init. Returns a pointer the the new local cache in case of success; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddLocalCacheInit]

Definition at line 265 of file cuddLCache.c.

267 {
268  cache->manager->memused -=
269  cache->slots * cache->itemsize + sizeof(DdLocalCache);
271  FREE(cache->item);
272  FREE(cache);
273 
274  return;
275 
276 } /* end of cuddLocalCacheQuit */
static void cuddLocalCacheRemoveFromList(DdLocalCache *cache)
Definition: cuddLCache.c:1366
#define FREE(obj)
Definition: util.h:80
DdLocalCacheItem * item
Definition: cuddInt.h:266
unsigned int itemsize
Definition: cuddInt.h:267
unsigned int slots
Definition: cuddInt.h:269
unsigned long memused
Definition: cuddInt.h:429
struct DdLocalCache DdLocalCache
DdManager * manager
Definition: cuddInt.h:275

◆ cuddLocalCacheRemoveFromList()

static void cuddLocalCacheRemoveFromList ( DdLocalCache cache)
static

Function********************************************************************

Synopsis [Removes a local cache from the manager list.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1366 of file cuddLCache.c.

1368 {
1369  DdManager *manager = cache->manager;
1370  DdLocalCache **prevCache, *nextCache;
1371 
1372  prevCache = &(manager->localCaches);
1373  nextCache = manager->localCaches;
1374 
1375  while (nextCache != NULL) {
1376  if (nextCache == cache) {
1377  *prevCache = nextCache->next;
1378  return;
1379  }
1380  prevCache = &(nextCache->next);
1381  nextCache = nextCache->next;
1382  }
1383  return; /* should never get here */
1384 
1385 } /* end of cuddLocalCacheRemoveFromList */
struct DdLocalCache * next
Definition: cuddInt.h:276
DdLocalCache * localCaches
Definition: cuddInt.h:417
DdManager * manager
Definition: cuddInt.h:275

◆ cuddLocalCacheResize()

static void cuddLocalCacheResize ( DdLocalCache cache)
static

AutomaticStart

Function********************************************************************

Synopsis [Resizes a local cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1231 of file cuddLCache.c.

1233 {
1234  DdLocalCacheItem *item, *olditem, *entry, *old;
1235  int i, shift;
1236  unsigned int posn;
1237  unsigned int slots, oldslots;
1238  extern DD_OOMFP MMoutOfMemory;
1239  DD_OOMFP saveHandler;
1240 
1241  olditem = cache->item;
1242  oldslots = cache->slots;
1243  slots = cache->slots = oldslots << 1;
1244 
1245 #ifdef DD_VERBOSE
1246  (void) fprintf(cache->manager->err,
1247  "Resizing local cache from %d to %d entries\n",
1248  oldslots, slots);
1249  (void) fprintf(cache->manager->err,
1250  "\thits = %.0f\tlookups = %.0f\thit ratio = %5.3f\n",
1251  cache->hits, cache->lookUps, cache->hits / cache->lookUps);
1252 #endif
1253 
1254  saveHandler = MMoutOfMemory;
1255  MMoutOfMemory = Cudd_OutOfMem;
1256  cache->item = item =
1257  (DdLocalCacheItem *) ALLOC(char, slots * cache->itemsize);
1258  MMoutOfMemory = saveHandler;
1259  /* If we fail to allocate the new table we just give up. */
1260  if (item == NULL) {
1261 #ifdef DD_VERBOSE
1262  (void) fprintf(cache->manager->err,"Resizing failed. Giving up.\n");
1263 #endif
1264  cache->slots = oldslots;
1265  cache->item = olditem;
1266  /* Do not try to resize again. */
1267  cache->maxslots = oldslots - 1;
1268  return;
1269  }
1270  shift = --(cache->shift);
1271  cache->manager->memused += (slots - oldslots) * cache->itemsize;
1272 
1273  /* Clear new cache. */
1274  memset(item, 0, slots * cache->itemsize);
1275 
1276  /* Copy from old cache to new one. */
1277  for (i = 0; (unsigned) i < oldslots; i++) {
1278  old = (DdLocalCacheItem *) ((char *) olditem + i * cache->itemsize);
1279  if (old->value != NULL) {
1280  posn = ddLCHash(old->key,cache->keysize,shift);
1281  entry = (DdLocalCacheItem *) ((char *) item +
1282  posn * cache->itemsize);
1283  memcpy(entry->key,old->key,cache->keysize*sizeof(DdNode *));
1284  entry->value = old->value;
1285  }
1286  }
1287 
1288  FREE(olditem);
1289 
1290  /* Reinitialize measurements so as to avoid division by 0 and
1291  ** immediate resizing.
1292  */
1293  cache->lookUps = (double) (int) (slots * cache->minHit + 1);
1294  cache->hits = 0;
1295 
1296 } /* end of cuddLocalCacheResize */
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2845
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
char * memcpy()
FILE * err
Definition: cuddInt.h:424
DdNode * value
Definition: cuddInt.h:257
double minHit
Definition: cuddInt.h:272
unsigned int keysize
Definition: cuddInt.h:268
DdLocalCacheItem * item
Definition: cuddInt.h:266
void(* DD_OOMFP)(long)
Definition: cudd.h:311
static int * entry
Definition: cuddGroup.c:119
unsigned int maxslots
Definition: cuddInt.h:274
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1313
char * memset()
unsigned int itemsize
Definition: cuddInt.h:267
#define ALLOC(type, num)
Definition: util.h:76
double hits
Definition: cuddInt.h:273
double lookUps
Definition: cuddInt.h:271
unsigned int slots
Definition: cuddInt.h:269
void(* MMoutOfMemory)(long)
Definition: safe_mem.c:32
unsigned long memused
Definition: cuddInt.h:429
DdNode * key[1]
Definition: cuddInt.h:261
DdManager * manager
Definition: cuddInt.h:275

◆ ddLCHash()

static DD_INLINE unsigned int ddLCHash ( DdNodePtr key,
unsigned int  keysize,
int  shift 
)
static

Function********************************************************************

Synopsis [Computes the hash value for a local cache.]

Description [Computes the hash value for a local cache. Returns the bucket index.]

SideEffects [None]

SeeAlso []

Definition at line 1313 of file cuddLCache.c.

1317 {
1318  unsigned int val = (unsigned int) (ptrint) key[0] * DD_P2;
1319  unsigned int i;
1320 
1321  for (i = 1; i < keysize; i++) {
1322  val = val * DD_P1 + (int) (ptrint) key[i];
1323  }
1324 
1325  return(val >> shift);
1326 
1327 } /* end of ddLCHash */
int ptrint
Definition: cuddInt.h:249
#define DD_P2
Definition: cuddInt.h:157
#define DD_P1
Definition: cuddInt.h:156

Variable Documentation

◆ DD_UNUSED

char rcsid [] DD_UNUSED = "$Id: cuddLCache.c,v 1.27 2012/02/05 01:07:19 fabio Exp $"
static

Definition at line 102 of file cuddLCache.c.