2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 static char rcsid[] = "$Id: hash.c,v 1.2 2001-01-31 15:18:04 bradleyb Exp $";
31 int hashtable_init( hashtable *ht, int size ) {
36 for (i=1; i<13; i++ ) {
37 if ( (1<<i) >= size ) {
44 ht->and_mask = ht->size - 1;
46 Error( "Hashtable has size of 0" );
48 ht->key = (char **)d_malloc( size * sizeof(char *) );
50 Error( "Not enough memory to create a hash table of size %d", size );
52 for (i=0; i<size; i++ )
55 // Use calloc cause we want zero'd array.
56 ht->value = d_malloc( size*sizeof(int) );
57 if (ht->value==NULL) {
59 Error( "Not enough memory to create a hash table of size %d\n", size );
67 void hashtable_free( hashtable *ht ) {
70 if (ht->value != NULL )
75 int hashtable_getkey( char *key ) {
79 k^=((int)(*key++))<<i;
85 int hashtable_search( hashtable *ht, char *key ) {
90 k = hashtable_getkey( key );
93 while(i < ht->size ) {
94 j = (k+(i++)) & ht->and_mask;
95 if ( ht->key[j] == NULL )
97 if (!stricmp(ht->key[j], key ))
103 void hashtable_insert( hashtable *ht, char *key, int value ) {
107 k = hashtable_getkey( key );
110 while(i < ht->size) {
111 j = (k+(i++)) & ht->and_mask;
112 if ( ht->key[j] == NULL ) {
115 ht->value[j] = value;
117 } else if (!stricmp( key, ht->key[j] )) {
121 Error( "Out of hash slots\n" );