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 library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or (at
12 * your 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 /*******************************************************************************
27 * Tool : Spice parser / driver v 7.00 *
28 * Author(s) : Gregoire AVOT *
29 * Updates : March, 18th 1998 *
31 *******************************************************************************/
40 extern char SPI_CASE_SENSITIVE
;
42 /* 2^n elements dans la table de hash */
46 /* 2^n Seuil d'augmentation */
55 new = ( thash
* )mbkalloc( sizeof( thash
) );
56 new->entree
= HASH_MINI
;
58 new->table
= ( hashelem
** )mbkalloc( sizeof( hashelem
* ) * n
);
63 for( i
= 0 ; i
< n
; i
++ )
72 chain_list
*scanchain
;
80 for( scanchain
= pt
->libere
; scanchain
; scanchain
= scanchain
->NEXT
)
81 mbkfree( scanchain
->DATA
);
82 freechain( pt
->libere
);
87 hashelem
* nouvhashelem( table
)
95 table
->tete
= ( hashelem
* ) mbkalloc ( sizeof( hashelem
) * 64 );
96 table
->libere
= addchain( table
->libere
, table
->tete
);
99 for( i
= 1 ; i
< 64 ; i
++ )
101 elem
->suivant
= elem
+ 1;
104 elem
->suivant
= NULL
;
108 table
->tete
= table
->tete
->suivant
;
113 void liberehashelem( table
, elem
)
117 elem
->suivant
= table
->tete
;
121 void addthashelem( nouveau
, ptr
, table
)
130 if( table
->nbelem
== 1 << ( table
->entree
+ HASH_DELTA
) &&
131 table
->entree
< HASH_MAXI
)
132 resizetable( table
, table
->entree
+ 1 );
134 s
= thashsignature( nouveau
, table
->entree
);
135 elm
= nouvhashelem( table
);
137 elm
->suivant
= table
->table
[ s
];
138 table
->table
[ s
] = elm
;
146 void* getthashelem( elem
, table
, status
)
154 s
= thashsignature( elem
, table
->entree
);
156 for( scan
= table
->table
[ s
] ; scan
; scan
= scan
->suivant
)
158 if( /*scan->mot == elem ||*/ strcasecmp( scan
->mot
, elem
) == 0 )
172 int thashsignature( c
, l
)
185 for( bit
= 0; bit
< 8 ; bit
++ )
187 if (CASE_SENSITIVE
!= 'P') b
= ( *c
>> bit
) & 0x1;
188 else b
= ( tolower((int)*c
) >> bit
) & 0x1;
190 /* Polynome générateur : X^15 + X + 1 */
191 dec
= ( ( dec
& 0x3FFE ) << 1 ) |
192 ( ( ( dec
& 0x4000 ) >> 13 ) ^ ( ( dec
& 0x1 ) << 1 ) ) |
193 ( ( ( dec
& 0x4000 ) >> 14 ) ^ b
) ;
198 return( dec
% ( 1 << l
) );
201 void resizetable( table
, elem
)
215 new = ( hashelem
** )mbkalloc( sizeof( hashelem
* ) * n
);
216 for( i
= 0 ; i
< n
; i
++ )
219 n
= 1 << table
->entree
;
221 for( i
= 0 ; i
< n
; i
++ )
223 for( scan
= table
->table
[i
] ; scan
; scan
= scan
->suivant
)
225 nouv
= nouvhashelem( table
);
226 s
= thashsignature( scan
->mot
, elem
);
228 nouv
->suivant
= new[ s
];
230 nouv
->mot
= scan
->mot
;
231 nouv
->ptr
= scan
->ptr
;
234 for( scan
= table
->table
[i
] ; scan
; scan
= suiv
)
236 suiv
= scan
->suivant
;
237 liberehashelem( table
, scan
);
241 mbkfree( table
->table
);
243 table
->entree
= elem
;