@@ -42,7 +42,6 @@ void *xrealloc();
42
42
static void rehash ();
43
43
44
44
#define max (a ,b ) ((a) > (b) ? (a) : (b))
45
- #define nil (type ) ((type*)0)
46
45
#define alloc (type ) (type*)xmalloc((unsigned)sizeof(type))
47
46
#define Calloc (n ,s ) (char*)xcalloc((n),(s))
48
47
@@ -100,18 +99,18 @@ st_free_table(table)
100
99
101
100
for (i = 0 ; i < table -> num_bins ; i ++ ) {
102
101
ptr = table -> bins [i ];
103
- while (ptr != nil ( st_table_entry ) ) {
102
+ while (ptr != 0 ) {
104
103
next = ptr -> next ;
105
- free (( char * ) ptr );
104
+ free (ptr );
106
105
ptr = next ;
107
106
}
108
107
}
109
- free (( char * ) table -> bins );
110
- free (( char * ) table );
108
+ free (table -> bins );
109
+ free (table );
111
110
}
112
111
113
112
#define PTR_NOT_EQUAL (table , ptr , key ) \
114
- (ptr != nil(st_table_entry) && !EQUAL(table, key, (ptr)->key))
113
+ (ptr != 0 && !EQUAL(table, key, (ptr)->key))
115
114
116
115
#define FIND_ENTRY (table , ptr , hash_val ) \
117
116
ptr = (table)->bins[hash_val];\
@@ -135,10 +134,10 @@ st_lookup(table, key, value)
135
134
136
135
FIND_ENTRY (table , ptr , hash_val );
137
136
138
- if (ptr == nil ( st_table_entry ) ) {
137
+ if (ptr == 0 ) {
139
138
return 0 ;
140
139
} else {
141
- if (value != nil ( char * ) ) * value = ptr -> record ;
140
+ if (value != 0 ) * value = ptr -> record ;
142
141
return 1 ;
143
142
}
144
143
}
@@ -173,7 +172,7 @@ st_insert(table, key, value)
173
172
174
173
FIND_ENTRY (table , ptr , hash_val );
175
174
176
- if (ptr == nil ( st_table_entry ) ) {
175
+ if (ptr == 0 ) {
177
176
ADD_DIRECT (table ,key ,value ,hash_val ,tbl );
178
177
return 0 ;
179
178
} else {
@@ -208,12 +207,12 @@ st_find_or_add(table, key, slot)
208
207
209
208
FIND_ENTRY (table , ptr , hash_val );
210
209
211
- if (ptr == nil ( st_table_entry ) ) {
210
+ if (ptr == 0 ) {
212
211
ADD_DIRECT (table , key , (char * )0 , hash_val , tbl )
213
- if (slot != nil ( char * * ) ) * slot = & tbl -> record ;
212
+ if (slot != 0 ) * slot = & tbl -> record ;
214
213
return 0 ;
215
214
} else {
216
- if (slot != nil ( char * * ) ) * slot = & ptr -> record ;
215
+ if (slot != 0 ) * slot = & ptr -> record ;
217
216
return 1 ;
218
217
}
219
218
}
@@ -222,7 +221,7 @@ static void
222
221
rehash (table )
223
222
register st_table * table ;
224
223
{
225
- register st_table_entry * ptr , * next , * * old_bins = table -> bins ;
224
+ register st_table_entry * ptr , * next , * * new_bins ;
226
225
int i , old_num_bins = table -> num_bins , new_num_bins , hash_val ;
227
226
228
227
new_num_bins = 1.79 * old_num_bins ;
@@ -231,24 +230,22 @@ rehash(table)
231
230
new_num_bins += 1 ;
232
231
}
233
232
234
- table -> num_bins = 0 ;
235
- table -> num_entries = 0 ;
236
- table -> bins = (st_table_entry * * )
233
+ new_bins = (st_table_entry * * )
237
234
Calloc ((unsigned )new_num_bins , sizeof (st_table_entry * ));
238
235
239
236
for (i = 0 ; i < old_num_bins ; i ++ ) {
240
- ptr = old_bins [i ];
241
- while (ptr != nil ( st_table_entry ) ) {
237
+ ptr = table -> bins [i ];
238
+ while (ptr != 0 ) {
242
239
next = ptr -> next ;
243
240
hash_val = do_hash2 (ptr -> key , table , new_num_bins );
244
- ptr -> next = table -> bins [hash_val ];
245
- table -> bins [hash_val ] = ptr ;
246
- table -> num_entries ++ ;
241
+ ptr -> next = new_bins [hash_val ];
242
+ new_bins [hash_val ] = ptr ;
247
243
ptr = next ;
248
244
}
249
245
}
246
+ free (table -> bins );
250
247
table -> num_bins = new_num_bins ;
251
- free (( char * ) old_bins ) ;
248
+ table -> bins = new_bins ;
252
249
}
253
250
254
251
st_table *
@@ -260,28 +257,28 @@ st_copy(old_table)
260
257
int i , num_bins = old_table -> num_bins ;
261
258
262
259
new_table = alloc (st_table );
263
- if (new_table == nil ( st_table ) ) {
264
- return nil ( st_table ) ;
260
+ if (new_table == 0 ) {
261
+ return 0 ;
265
262
}
266
263
267
264
* new_table = * old_table ;
268
265
new_table -> bins = (st_table_entry * * )
269
266
Calloc ((unsigned )num_bins , sizeof (st_table_entry * ));
270
267
271
- if (new_table -> bins == nil ( st_table_entry * ) ) {
272
- free (( char * ) new_table );
273
- return nil ( st_table ) ;
268
+ if (new_table -> bins == 0 ) {
269
+ free (new_table );
270
+ return 0 ;
274
271
}
275
272
276
273
for (i = 0 ; i < num_bins ; i ++ ) {
277
- new_table -> bins [i ] = nil ( st_table_entry ) ;
274
+ new_table -> bins [i ] = 0 ;
278
275
ptr = old_table -> bins [i ];
279
- while (ptr != nil ( st_table_entry ) ) {
276
+ while (ptr != 0 ) {
280
277
tbl = alloc (st_table_entry );
281
- if (tbl == nil ( st_table_entry ) ) {
282
- free (( char * ) new_table -> bins );
283
- free (( char * ) new_table );
284
- return nil ( st_table ) ;
278
+ if (tbl == 0 ) {
279
+ free (new_table -> bins );
280
+ free (new_table );
281
+ return 0 ;
285
282
}
286
283
* tbl = * ptr ;
287
284
tbl -> next = new_table -> bins [i ];
@@ -306,28 +303,28 @@ st_delete(table, key, value)
306
303
307
304
ptr = table -> bins [hash_val ];
308
305
309
- if (ptr == nil ( st_table_entry ) ) {
310
- if (value != nil ( char * )) * value = nil ( char ) ;
306
+ if (ptr == 0 ) {
307
+ if (value != 0 ) * value = 0 ;
311
308
return 0 ;
312
309
}
313
310
314
311
if (EQUAL (table , * key , ptr -> key )) {
315
312
table -> bins [hash_val ] = ptr -> next ;
316
313
table -> num_entries -- ;
317
- if (value != nil ( char * ) ) * value = ptr -> record ;
314
+ if (value != 0 ) * value = ptr -> record ;
318
315
* key = ptr -> key ;
319
- free (( char * ) ptr );
316
+ free (ptr );
320
317
return 1 ;
321
318
}
322
319
323
- for (; ptr -> next != nil ( st_table_entry ) ; ptr = ptr -> next ) {
320
+ for (; ptr -> next != 0 ; ptr = ptr -> next ) {
324
321
if (EQUAL (table , ptr -> next -> key , * key )) {
325
322
tmp = ptr -> next ;
326
323
ptr -> next = ptr -> next -> next ;
327
324
table -> num_entries -- ;
328
- if (value != nil ( char * ) ) * value = tmp -> record ;
325
+ if (value != 0 ) * value = tmp -> record ;
329
326
* key = tmp -> key ;
330
- free (( char * ) tmp );
327
+ free (tmp );
331
328
return 1 ;
332
329
}
333
330
}
@@ -349,24 +346,24 @@ st_delete_safe(table, key, value, never)
349
346
350
347
ptr = table -> bins [hash_val ];
351
348
352
- if (ptr == nil ( st_table_entry ) ) {
353
- if (value != nil ( char * )) * value = nil ( char ) ;
349
+ if (ptr == 0 ) {
350
+ if (value != 0 ) * value = 0 ;
354
351
return 0 ;
355
352
}
356
353
357
354
if (EQUAL (table , * key , ptr -> key )) {
358
355
table -> num_entries -- ;
359
356
* key = ptr -> key ;
360
- if (value != nil ( char * ) ) * value = ptr -> record ;
357
+ if (value != 0 ) * value = ptr -> record ;
361
358
ptr -> key = ptr -> record = never ;
362
359
return 1 ;
363
360
}
364
361
365
- for (; ptr -> next != nil ( st_table_entry ) ; ptr = ptr -> next ) {
362
+ for (; ptr -> next != 0 ; ptr = ptr -> next ) {
366
363
if (EQUAL (table , ptr -> next -> key , * key )) {
367
364
table -> num_entries -- ;
368
365
* key = ptr -> key ;
369
- if (value != nil ( char * ) ) * value = ptr -> record ;
366
+ if (value != 0 ) * value = ptr -> record ;
370
367
ptr -> key = ptr -> record = never ;
371
368
return 1 ;
372
369
}
@@ -386,8 +383,8 @@ st_foreach(table, func, arg)
386
383
int i ;
387
384
388
385
for (i = 0 ; i < table -> num_bins ; i ++ ) {
389
- last = nil ( st_table_entry ) ;
390
- for (ptr = table -> bins [i ]; ptr != nil ( st_table_entry ) ;) {
386
+ last = 0 ;
387
+ for (ptr = table -> bins [i ]; ptr != 0 ;) {
391
388
retval = (* func )(ptr -> key , ptr -> record , arg );
392
389
switch (retval ) {
393
390
case ST_CONTINUE :
@@ -398,13 +395,13 @@ st_foreach(table, func, arg)
398
395
return ;
399
396
case ST_DELETE :
400
397
tmp = ptr ;
401
- if (last == nil ( st_table_entry ) ) {
398
+ if (last == 0 ) {
402
399
table -> bins [i ] = ptr -> next ;
403
400
} else {
404
401
last -> next = ptr -> next ;
405
402
}
406
403
ptr = ptr -> next ;
407
- free (( char * ) tmp );
404
+ free (tmp );
408
405
table -> num_entries -- ;
409
406
}
410
407
}
0 commit comments