Skip to content

Commit 942fb89

Browse files
committed
cleanup
1 parent 893936b commit 942fb89

File tree

5 files changed

+83
-187
lines changed

5 files changed

+83
-187
lines changed

src/clutils/sc_hash.cc

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* "$Id: sc_hash.cc,v 3.0.1.2 1997/11/05 22:33:50 sauderd DP3.1 $"; */
2-
3-
/*
1+
/** \file sc_hash.cc
42
* Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson.
53
* Coded into C, with minor code improvements, and with hsearch(3) interface,
64
* by ejp@ausmelb.oz, Jul 26, 1988: 13:16;
@@ -13,57 +11,40 @@
1311
#include <string.h>
1412
#include <sc_memmgr.h>
1513

16-
/*************/
1714
/* constants */
18-
/*************/
19-
2015
#define HASH_NULL (Hash_TableP)NULL
21-
2216
#define SEGMENT_SIZE 256
2317
#define SEGMENT_SIZE_SHIFT 8 /* log2(SEGMENT_SIZE) */
2418
#define PRIME1 37
2519
#define PRIME2 1048583
2620
#define MAX_LOAD_FACTOR 5
2721

28-
/************/
29-
/* typedefs */
30-
/************/
31-
32-
typedef unsigned long Address;
33-
34-
/******************************/
3522
/* macro function definitions */
36-
/******************************/
37-
38-
/*
39-
** Fast arithmetic, relying on powers of 2
40-
*/
41-
42-
#define MUL(x,y) ((x) << (y##_SHIFT))
43-
#define DIV(x,y) ((x) >> (y##_SHIFT))
44-
#define MOD(x,y) ((x) & ((y)-1))
45-
4623
#define SC_HASH_Table_new() new Hash_Table
4724
#define SC_HASH_Table_destroy(x) delete x
4825
#define SC_HASH_Element_new() new Element
4926
#define SC_HASH_Element_destroy(x) delete x
5027

28+
/* Macros for fast arithmetic, relying on powers of 2 */
29+
#define MUL(x,y) ((x) << (y##_SHIFT))
30+
#define DIV(x,y) ((x) >> (y##_SHIFT))
31+
#define MOD(x,y) ((x) & ((y)-1))
32+
33+
/* typedefs */
34+
typedef unsigned long Address;
5135
typedef struct Element * ElementP;
5236
typedef struct Hash_Table * Hash_TableP;
5337

54-
/*
55-
** Internal routines
56-
*/
57-
38+
/* Internal routines */
5839
Address SC_HASHhash( char *, Hash_TableP );
5940
static void SC_HASHexpand_table( Hash_TableP );
6041

6142
# ifdef HASH_STATISTICS
6243
static long HashAccesses, HashCollisions;
6344
# endif
6445

65-
void *
66-
SC_HASHfind( Hash_TableP t, char * s ) {
46+
/// find entry in given hash table
47+
void * SC_HASHfind( Hash_TableP t, char * s ) {
6748
struct Element e;
6849
struct Element * ep;
6950

@@ -73,8 +54,8 @@ SC_HASHfind( Hash_TableP t, char * s ) {
7354
return( ep ? ep->data : 0 );
7455
}
7556

76-
void
77-
SC_HASHinsert( Hash_TableP t, char * s, void * data ) {
57+
/// insert entry into given hash table
58+
void SC_HASHinsert( Hash_TableP t, char * s, void * data ) {
7859
struct Element e, *e2;
7960

8061
e.key = s;
@@ -86,8 +67,8 @@ SC_HASHinsert( Hash_TableP t, char * s, void * data ) {
8667
}
8768
}
8869

89-
Hash_TableP
90-
SC_HASHcreate( unsigned count ) {
70+
/// create a hash table
71+
Hash_TableP SC_HASHcreate( unsigned count ) {
9172
unsigned int i;
9273
Hash_TableP table;
9374

@@ -138,29 +119,26 @@ SC_HASHcreate( unsigned count ) {
138119
return( table );
139120
}
140121

141-
/* initialize pointer to beginning of hash table so we can step through it */
142-
/* on repeated calls to HASHlist - DEL */
143-
void
144-
SC_HASHlistinit( Hash_TableP table, HashEntry * he ) {
122+
/** initialize pointer to beginning of hash table so we can
123+
* step through it on repeated calls to HASHlist - DEL */
124+
void SC_HASHlistinit( Hash_TableP table, HashEntry * he ) {
145125
he->i = he->j = 0;
146126
he->p = 0;
147127
he->table = table;
148128
he->type = '*';
149129
he->e = 0;
150130
}
151131

152-
void
153-
SC_HASHlistinit_by_type( Hash_TableP table, HashEntry * he, char type ) {
132+
void SC_HASHlistinit_by_type( Hash_TableP table, HashEntry * he, char type ) {
154133
he->i = he->j = 0;
155134
he->p = 0;
156135
he->table = table;
157136
he->type = type;
158137
he->e = 0;
159138
}
160139

161-
/* provide a way to step through the hash */
162-
struct Element *
163-
SC_HASHlist( HashEntry * he ) {
140+
/** provide a way to step through the hash */
141+
struct Element * SC_HASHlist( HashEntry * he ) {
164142
int i2 = he->i;
165143
int j2 = he->j;
166144
struct Element ** s;
@@ -202,8 +180,8 @@ SC_HASHlist( HashEntry * he ) {
202180
return( he->e );
203181
}
204182

205-
void
206-
SC_HASHdestroy( Hash_TableP table ) {
183+
/// destroy all elements in given table, then the table itself
184+
void SC_HASHdestroy( Hash_TableP table ) {
207185
struct Element ** s;
208186
struct Element * p, *q;
209187

@@ -226,16 +204,13 @@ SC_HASHdestroy( Hash_TableP table ) {
226204
}
227205
SC_HASH_Table_destroy( table );
228206
# if defined(HASH_STATISTICS) && defined(DEBUG)
229-
fprintf( stderr,
230-
"[hdestroy] Accesses %ld Collisions %ld\n",
231-
HashAccesses,
232-
HashCollisions );
207+
fprintf( stderr, "[hdestroy] Accesses %ld Collisions %ld\n", HashAccesses, HashCollisions );
233208
# endif
234209
}
235210
}
236211

237-
struct Element *
238-
SC_HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
212+
/// search table for 'item', perform 'action' (find/insert/delete)
213+
struct Element * SC_HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
239214
Address h;
240215
struct Element ** CurrentSegment;
241216
int SegmentIndex;
@@ -317,8 +292,7 @@ SC_HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
317292
** Internal routines
318293
*/
319294

320-
Address
321-
SC_HASHhash( char * Key, Hash_TableP table ) {
295+
Address SC_HASHhash( char * Key, Hash_TableP table ) {
322296
Address h, address;
323297
register unsigned char * k = ( unsigned char * )Key;
324298

@@ -337,9 +311,7 @@ SC_HASHhash( char * Key, Hash_TableP table ) {
337311
return( address );
338312
}
339313

340-
static
341-
void
342-
SC_HASHexpand_table( Hash_TableP table ) {
314+
static void SC_HASHexpand_table( Hash_TableP table ) {
343315
struct Element ** OldSegment, **NewSegment;
344316
struct Element * Current, **Previous, **LastOfNew;
345317

@@ -407,7 +379,7 @@ SC_HASHexpand_table( Hash_TableP table ) {
407379
}
408380
}
409381

410-
/* following code is for testing hash package */
382+
/* for testing sc_hash */
411383
#ifdef HASHTEST
412384
struct Element e1, e2, e3, *e;
413385
struct Hash_Table * t;

src/exp2cxx/classes_type.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ int isMultiDimAggregateType( const Type t );
4343
void Type_Description( const Type, char * );
4444
void TypeBody_Description( TypeBody body, char * buf );
4545

46+
/** write representation of expression to end of buf
47+
*
48+
* TODO: add buflen arg and check for overflow
49+
*/
4650
void strcat_expr( Expression e, char * buf ) {
4751
if( e == LITERAL_INFINITY ) {
4852
strcat( buf, "?" );
@@ -65,7 +69,10 @@ void strcat_expr( Expression e, char * buf ) {
6569
}
6670
}
6771

68-
/** print t's bounds to end of buf */
72+
/** print t's bounds to end of buf
73+
*
74+
* TODO: add buflen arg and check for overflow
75+
*/
6976
void strcat_bounds( TypeBody b, char * buf ) {
7077
if( !b->upper ) {
7178
return;
@@ -94,7 +101,6 @@ void strcat_bounds( TypeBody b, char * buf ) {
94101
** Change Date: 5/22/91 CD
95102
******************************************************************/
96103
const char * EnumCElementName( Type type, Expression expr ) {
97-
98104
static char buf [BUFSIZ];
99105
sprintf( buf, "%s__",
100106
EnumName( TYPEget_name( type ) ) );
@@ -104,7 +110,6 @@ const char * EnumCElementName( Type type, Expression expr ) {
104110
}
105111

106112
char * CheckEnumSymbol( char * s ) {
107-
108113
static char b [BUFSIZ];
109114
if( strcmp( s, "sdaiTRUE" )
110115
&& strcmp( s, "sdaiFALSE" )

src/exp2python/src/classes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const char * TYPEget_ctype( const Type t );
129129
void print_file( Express );
130130
void resolution_success( void );
131131
void SCHEMAprint( Schema schema, FILES* files, int suffix );
132-
Type TYPEget_ancestor( Type );
132+
Type TYPEget_ancestor( Type t );
133133
const char * FundamentalType( const Type t, int report_reftypes );
134134

135135
/*Variable*/

0 commit comments

Comments
 (0)