00001
00002
00003
00004 #include "bddint.h"
00005
00006
00007 #define HASH(d) ((INT_PTR)(d))
00008
00009
00010
00011
00012
00013 static
00014 void
00015 bdd_rehash_hash_table(hash_table h)
00016 {
00017 long i;
00018 long hash;
00019 long oldsize;
00020 hash_rec *newtable;
00021 hash_rec p, q;
00022
00023 oldsize=h->size;
00024 h->size_index++;
00025 h->size=TABLE_SIZE(h->size_index);
00026 newtable=(hash_rec *)mem_get_block((SIZE_T)(h->size*sizeof(hash_rec)));
00027 for (i=0; i < h->size; ++i)
00028 newtable[i]=0;
00029 for (i=0; i < oldsize; ++i)
00030 for (p=h->table[i]; p; p=q)
00031 {
00032 q=p->next;
00033 hash=HASH(p->key);
00034 BDD_REDUCE(hash, h->size);
00035 p->next=newtable[hash];
00036 newtable[hash]=p;
00037 }
00038 mem_free_block((pointer)h->table);
00039 h->table=newtable;
00040 }
00041
00042
00043
00044
00045
00046 void
00047 bdd_insert_in_hash_table(hash_table h, bdd f, pointer data)
00048 {
00049 long hash;
00050 hash_rec p;
00051
00052 p=(hash_rec)BDD_NEW_REC(h->bddm, ALIGN(sizeof(struct hash_rec_))+h->item_size);
00053 p->key=f;
00054 mem_copy((pointer)(ALIGN(sizeof(struct hash_rec_))+(INT_PTR)p), data, (SIZE_T)h->item_size);
00055 hash=HASH(f);
00056 BDD_REDUCE(hash, h->size);
00057 p->next=h->table[hash];
00058 h->table[hash]=p;
00059 h->entries++;
00060 if ((h->size << 2) < h->entries)
00061 bdd_rehash_hash_table(h);
00062 }
00063
00064
00065
00066
00067
00068 pointer
00069 bdd_lookup_in_hash_table(hash_table h, bdd f)
00070 {
00071 long hash;
00072 hash_rec p;
00073
00074 hash=HASH(f);
00075 BDD_REDUCE(hash, h->size);
00076 for (p=h->table[hash]; p; p=p->next)
00077 if (p->key == f)
00078 return ((pointer)(ALIGN(sizeof(struct hash_rec_))+(char *)p));
00079 return ((pointer)0);
00080 }
00081
00082
00083
00084
00085
00086 hash_table
00087 bdd_new_hash_table(cmu_bdd_manager bddm, int item_size)
00088 {
00089 long i;
00090 hash_table h;
00091
00092 h=(hash_table)BDD_NEW_REC(bddm, sizeof(struct hash_table_));
00093 h->size_index=10;
00094 h->size=TABLE_SIZE(h->size_index);
00095 h->table=(hash_rec *)mem_get_block((SIZE_T)(h->size*sizeof(hash_rec)));
00096 for (i=0; i < h->size; ++i)
00097 h->table[i]=0;
00098 h->entries=0;
00099 h->item_size=item_size;
00100 h->bddm=bddm;
00101 return (h);
00102 }
00103
00104
00105
00106
00107 void
00108 cmu_bdd_free_hash_table(hash_table h)
00109 {
00110 long i;
00111 hash_rec p, q;
00112
00113 for (i=0; i < h->size; ++i)
00114 for (p=h->table[i]; p; p=q)
00115 {
00116 q=p->next;
00117 BDD_FREE_REC(h->bddm, (pointer)p, ALIGN(sizeof(struct hash_rec_))+h->item_size);
00118 }
00119 mem_free_block((pointer)h->table);
00120 BDD_FREE_REC(h->bddm, (pointer)h, sizeof(struct hash_table_));
00121 }