2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - Département ASIM
4 * Universite Pierre et Marie Curie
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail support : mailto:alliance-support@asim.lip6.fr
9 * This progam is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * Alliance VLSI CAD System is distributed in the hope that it will be
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with the GNU C Library; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Tool : ABL, BDD, HT Librarie
28 * Modified by Czo <Olivier.Sirol@lip6.fr> 1996,97
33 #ident "$Id: log_thashbdd.c,v 1.5 2006/03/20 10:44:20 fabrice Exp $"
35 /*--------------------------------------------------------------------------
36 la table de hachage des BDD
37 la version du 10.12.90
38 -------------------------------------------------------------------------- */
46 #define NB_APPEL_MAX 50
48 /* les fonction de l'utilisateurs :
49 ------------------------------
51 initialisation au depart des pointeurs de vertex a NULL.
52 un pointeur de Vertex desalloue est mis a BDDDELETE.
53 Les fonctions qui utilisent le hachage peuvent renvoye BDDTABLE_PLEINE
54 si la table est trop remplie.
58 pTableBdd createTableBdd(len)
61 b. destruction de la table
66 c. re-allocation d'une table de hachage
71 d. recherche d'un element
73 pNode searchTableBdd(pTab,index,high,low)
80 int addTableBdd(pTab,pBdd)
84 f. destruction d'un element
86 int deleteTableBdd(pTab,key)
90 g. affichage total d'une table
95 h. le garbage collector d'une table de hachage
97 void gcTableBdd(pTab);
103 /*-------------------- la fonction de hachage ---------------------------- */
106 hashBdd (index
, high
, low
)
110 return (abs (index
+ ((long) high
<< 1) + (long) low
+
111 ((long) high
>> 4) + ((long) low
>> 5)));
114 /*--------------- la fonction de changement de cle ------------------------- */
117 newKeyBdd (index
, high
, low
)
121 return (index
+ (index
<< 2) + (long) high
+ ((long) low
<< 1));
124 /*--------------- La table de hachage pour des BDD ------------ */
126 /* la fonction de creation de table de hachage pour les BDD .
127 On alloue en premier lieu une structure TABLE, puis une table
128 qui n'est rien d'autre qu'un tableau de pointeurs de BDD. Il est
129 donc possible de travailler avec plusieurs tables a la fois. */
139 if (!(pTab
= (pTableBdd
) mbkalloc (sizeof (struct tableBdd
))))
141 avt_errmsg(LOG_ERRMSG
,"000",AVT_FATAL
,"160");
142 // printf ("impossible allocation\n");
145 pTab
->lenTableBdd
= len
;
147 if (!(pBdd
= (pNode
*) mbkalloc (len
* sizeof (pNode
))))
149 avt_errmsg(LOG_ERRMSG
,"000",AVT_FATAL
,"161");
150 // printf ("impossible allocation\n");
154 for (i
= 0; i
< len
; i
++)
163 /* destruction d'une table de hachage */
166 destroyTableBdd (pTab
)
176 /*------------------------------------------------------------------------------
177 markBddLst :met a jour les marques de l'ensemble des graphes de LstGdb.
178 -------------------------------------------------------
179 parametres :une liste LstGdb.
180 -------------------------------------------------------
182 ------------------------------------------------------------------------------*/
184 void markBddLst(pC,value)
190 pEl = (pC->pTO)->pElemT ;
192 for (i =0 ; i < (pC->pTO)->lenTable; i++)
194 if(pEl->value != VIDE && pEl->value != DELETE)
195 markBdd((pNode)pEl->value) ;
201 /* re-allocation d'une table de hachage devenue trop petite... */
204 reAllocTableBdd (pTab
)
211 if (pTab
->lenTableBdd
> MAX_SIZE_BDD
)
213 avt_errmsg(LOG_ERRMSG
,"002",AVT_FATAL
);
214 // printf ("BDD's system : not enough memory...\n");
217 pTabBis
= createTableBdd (pTab
->lenTableBdd
* 3); /* trois fois plus grande */
219 for (i
= 0; i
< pTab
->lenTableBdd
; i
++)
221 if (*pBdd
!= NULL
&& *pBdd
!= BDDDELETE
) /* la recopie */
222 addTableBdd (pTabBis
, *pBdd
);
225 destroyTableBdd (pTab
);
229 /* recherche d'un element dans la table
230 renvoie NULL si la recherche echoue. */
233 searchTableBdd (pTab
, index
, high
, low
)
245 if (co
++ > NB_APPEL_MAX
)
246 return (BDDTABLE_PLEINE
);
247 indice
= hashBdd (key
, high
, low
) % pTab
->lenTableBdd
;
248 pBddCur
= *((pTab
->pBdd
) + indice
);
249 if (pBddCur
!= NULL
&& pBddCur
!= BDDDELETE
)
250 if (high
== pBddCur
->high
&&
251 low
== pBddCur
->low
&&
252 index
== pBddCur
->index
)
254 key
= newKeyBdd (key
, high
, low
);
256 while (pBddCur
!= NULL
);
260 /* ajout d'un element a la table */
264 addTableBdd (pTab
, pBdd
)
270 int index
= pBdd
->index
;
271 pNode high
= pBdd
->high
;
272 pNode low
= pBdd
->low
;
276 if (pTab
->compteur
++ > (pTab
->lenTableBdd
) * 8 / 10) /* remplissage au 8/10 */
277 return (TABLE_PLEINE
);
280 if (co
++ > NB_APPEL_MAX
)
281 return (TABLE_PLEINE
);
282 indice
= hashBdd (key
, high
, low
) % pTab
->lenTableBdd
;
283 pBddCur
= ((pTab
->pBdd
) + indice
);
284 if (*pBddCur
== NULL
|| *pBddCur
== BDDDELETE
)
287 return (indice
); /* retourne la place utilisee */
289 key
= newKeyBdd (key
, high
, low
);
295 /* elimination d'un element de la table */
299 deleteTableBdd (pTab
, pBdd
)
305 pNode high
= pBdd
->high
;
306 pNode low
= pBdd
->low
;
307 int key
= pBdd
->index
;
312 if (co
++ > NB_APPEL_MAX
)
313 return (TABLE_PLEINE
);
314 indice
= hashBdd (key
, high
, low
) % pTab
->lenTableBdd
;
315 pBddCur
= (pTab
->pBdd
) + indice
;
316 if (*pBddCur
!= NULL
&& *pBddCur
!= BDDDELETE
)
318 if (pBdd
== *pBddCur
)
320 *pBddCur
= BDDDELETE
;
324 key
= newKeyBdd (key
, high
, low
);
326 while (pBddCur
!= NULL
);
327 return ((long) NULL
);
330 /* affichage des elements de la table */
333 displayHashBdd (pTab
)
342 printf ("\n---------------------------------------------------------------");
343 printf ("---------\n AFFICHAGE DE LA TABLE DE HACHAGE\n\n");
345 for (i
= 0; i
< pTab
->lenTableBdd
; i
++)
347 if (*pBdd
!= NULL
&& *pBdd
!= BDDDELETE
)
350 printf ("****** indice %d ****** \n", i
);
351 displayBdd (*pBdd
, FALSE
);
356 printf ("\n****** Nombre de noeuds dans la table = %d\n", co
);