Added SCL_ prefix to hash functions of scl_hash.cc.

* Linking went wrong because functions from hash.c and scl_hash.cc had
  the same names. By adding SCL_ prefix to the scl_hash.cc function names
  this issue is resolved.
* Fixed minor issue in scl_hash.cc.
This commit is contained in:
davyw
2012-04-05 20:40:07 +02:00
parent 04f4c1da66
commit 4740f4d45c
3 changed files with 76 additions and 71 deletions
+38 -36
View File
@@ -26,11 +26,9 @@ static int uniqueNames( const char *, const SchRename * );
Registry::Registry( CF_init initFunct )
: col( 0 ), entity_cnt( 0 ), all_ents_cnt( 0 ) {
/* Registry tables aren't always initialized */
HASHinitialize();
primordialSwamp = HASHcreate( 1000 );
active_schemas = HASHcreate( 10 );
active_types = HASHcreate( 100 );
primordialSwamp = SCL_HASHcreate( 1000 );
active_schemas = SCL_HASHcreate( 10 );
active_types = SCL_HASHcreate( 100 );
t_sdaiINTEGER = new TypeDescriptor( "INTEGER", // Name
sdaiINTEGER, // FundamentalType
@@ -62,34 +60,38 @@ Registry::Registry( CF_init initFunct )
"Number" );
initFunct( *this );
HASHlistinit( active_types, &cur_type );
HASHlistinit( primordialSwamp, &cur_entity ); // initialize cur's
HASHlistinit( active_schemas, &cur_schema );
SCL_HASHlistinit( active_types, &cur_type );
SCL_HASHlistinit( primordialSwamp, &cur_entity ); // initialize cur's
SCL_HASHlistinit( active_schemas, &cur_schema );
}
Registry::~Registry() {
DeleteContents();
HASHdestroy( primordialSwamp );
HASHdestroy( active_schemas );
HASHdestroy( active_types );
SCL_HASHdestroy( primordialSwamp );
SCL_HASHdestroy( active_schemas );
SCL_HASHdestroy( active_types );
delete col;
}
void Registry::DeleteContents() {
// entities first
HASHlistinit( primordialSwamp, &cur_entity );
while( HASHlist( &cur_entity ) ) {
SCL_HASHlistinit( primordialSwamp, &cur_entity );
while( SCL_HASHlist( &cur_entity ) ) {
delete( EntityDescriptor * ) cur_entity.e->data;
}
// schemas
HASHlistinit( active_schemas, &cur_schema );
while( HASHlist( &cur_schema ) ) {
SCL_HASHlistinit( active_schemas, &cur_schema );
while( SCL_HASHlist( &cur_schema ) ) {
delete( Schema * ) cur_schema.e->data;
}
// types
SCL_HASHlistinit( active_types, &cur_type );
while ( SCL_HASHlist( &cur_type ) ) {
delete( TypeDescriptor * ) cur_type.e->data;
}
}
/**
@@ -107,9 +109,9 @@ const EntityDescriptor * Registry::FindEntity( const char * e, const char * schN
char schformat[BUFSIZ], altName[BUFSIZ];
if( check_case ) {
entd = ( EntityDescriptor * )HASHfind( primordialSwamp, ( char * )e );
entd = ( EntityDescriptor * )SCL_HASHfind( primordialSwamp, ( char * )e );
} else {
entd = ( EntityDescriptor * )HASHfind( primordialSwamp,
entd = ( EntityDescriptor * )SCL_HASHfind( primordialSwamp,
( char * )PrettyTmpName( e ) );
}
if( entd && schNm ) {
@@ -143,34 +145,34 @@ const EntityDescriptor * Registry::FindEntity( const char * e, const char * schN
const Schema * Registry::FindSchema( const char * n, int check_case ) const {
if( check_case ) {
return ( const Schema * ) HASHfind( active_schemas, ( char * ) n );
return ( const Schema * ) SCL_HASHfind( active_schemas, ( char * ) n );
}
return ( const Schema * ) HASHfind( active_schemas,
return ( const Schema * ) SCL_HASHfind( active_schemas,
( char * )PrettyTmpName( n ) );
}
const TypeDescriptor * Registry::FindType( const char * n, int check_case ) const {
if( check_case ) {
return ( const TypeDescriptor * ) HASHfind( active_types, ( char * ) n );
return ( const TypeDescriptor * ) SCL_HASHfind( active_types, ( char * ) n );
}
return ( const TypeDescriptor * ) HASHfind( active_types,
return ( const TypeDescriptor * ) SCL_HASHfind( active_types,
( char * )PrettyTmpName( n ) );
}
void Registry::ResetTypes() {
HASHlistinit( active_types, &cur_type );
SCL_HASHlistinit( active_types, &cur_type );
}
const TypeDescriptor * Registry::NextType() {
if( 0 == HASHlist( &cur_type ) ) {
if( 0 == SCL_HASHlist( &cur_type ) ) {
return 0;
}
return ( const TypeDescriptor * ) cur_type.e->data;
}
void Registry::AddEntity( const EntityDescriptor & e ) {
HASHinsert( primordialSwamp, ( char * ) e.Name(), ( EntityDescriptor * ) &e );
SCL_HASHinsert( primordialSwamp, ( char * ) e.Name(), ( EntityDescriptor * ) &e );
++entity_cnt;
++all_ents_cnt;
AddClones( e );
@@ -178,11 +180,11 @@ void Registry::AddEntity( const EntityDescriptor & e ) {
void Registry::AddSchema( const Schema & d ) {
HASHinsert( active_schemas, ( char * ) d.Name(), ( Schema * ) &d );
SCL_HASHinsert( active_schemas, ( char * ) d.Name(), ( Schema * ) &d );
}
void Registry::AddType( const TypeDescriptor & d ) {
HASHinsert( active_types, ( char * ) d.Name(), ( TypeDescriptor * ) &d );
SCL_HASHinsert( active_types, ( char * ) d.Name(), ( TypeDescriptor * ) &d );
}
/**
@@ -196,7 +198,7 @@ void Registry::AddClones( const EntityDescriptor & e ) {
const SchRename * alts = e.AltNameList();
while( alts ) {
HASHinsert( primordialSwamp, ( char * )alts->objName(),
SCL_HASHinsert( primordialSwamp, ( char * )alts->objName(),
( EntityDescriptor * )&e );
alts = alts->next;
}
@@ -239,20 +241,20 @@ void Registry::RemoveEntity( const char * n ) {
RemoveClones( *e );
}
tmp.key = ( char * ) n;
HASHsearch( primordialSwamp, &tmp, HASH_DELETE ) ? --entity_cnt : 0;
SCL_HASHsearch( primordialSwamp, &tmp, HASH_DELETE ) ? --entity_cnt : 0;
}
void Registry::RemoveSchema( const char * n ) {
struct Element tmp;
tmp.key = ( char * ) n;
HASHsearch( active_schemas, &tmp, HASH_DELETE );
SCL_HASHsearch( active_schemas, &tmp, HASH_DELETE );
}
void Registry::RemoveType( const char * n ) {
struct Element tmp;
tmp.key = ( char * ) n;
HASHsearch( active_types, &tmp, HASH_DELETE );
SCL_HASHsearch( active_types, &tmp, HASH_DELETE );
}
/**
@@ -265,7 +267,7 @@ void Registry::RemoveClones( const EntityDescriptor & e ) {
while( alts ) {
tmp = new Element;
tmp->key = ( char * ) alts->objName();
HASHsearch( primordialSwamp, tmp, HASH_DELETE );
SCL_HASHsearch( primordialSwamp, tmp, HASH_DELETE );
alts = alts->next;
}
}
@@ -297,23 +299,23 @@ int Registry::GetEntityCnt() {
}
void Registry::ResetEntities() {
HASHlistinit( primordialSwamp, &cur_entity );
SCL_HASHlistinit( primordialSwamp, &cur_entity );
}
const EntityDescriptor * Registry::NextEntity() {
if( 0 == HASHlist( &cur_entity ) ) {
if( 0 == SCL_HASHlist( &cur_entity ) ) {
return 0;
}
return ( const EntityDescriptor * ) cur_entity.e->data;
}
void Registry::ResetSchemas() {
HASHlistinit( active_schemas, &cur_schema );
SCL_HASHlistinit( active_schemas, &cur_schema );
}
const Schema * Registry::NextSchema() {
if( 0 == HASHlist( &cur_schema ) ) {
if( 0 == SCL_HASHlist( &cur_schema ) ) {
return 0;
}
return ( const Schema * ) cur_schema.e->data;
+29 -26
View File
@@ -43,10 +43,10 @@ typedef unsigned long Address;
#define DIV(x,y) ((x) >> (y##_SHIFT))
#define MOD(x,y) ((x) & ((y)-1))
#define HASH_Table_new() new Hash_Table
#define HASH_Table_destroy(x) delete x
#define HASH_Element_new() new Element
#define HASH_Element_destroy(x) delete x
#define SCL_HASH_Table_new() new Hash_Table
#define SCL_HASH_Table_destroy(x) delete x
#define SCL_HASH_Element_new() new Element
#define SCL_HASH_Element_destroy(x) delete x
typedef struct Element * ElementP;
typedef struct Hash_Table * Hash_TableP;
@@ -55,39 +55,39 @@ typedef struct Hash_Table * Hash_TableP;
** Internal routines
*/
Address HASHhash( char *, Hash_TableP );
static void HASHexpand_table( Hash_TableP );
Address SCL_HASHhash( char *, Hash_TableP );
static void SCL_HASHexpand_table( Hash_TableP );
# if HASH_STATISTICS
static long HashAccesses, HashCollisions;
# endif
void *
HASHfind( Hash_TableP t, char * s ) {
SCL_HASHfind( Hash_TableP t, char * s ) {
struct Element e;
struct Element * ep;
e.key = s;
e.symbol = 0; /* initialize to 0 - 25-Apr-1994 - kcm */
ep = HASHsearch( t, &e, HASH_FIND );
ep = SCL_HASHsearch( t, &e, HASH_FIND );
return( ep ? ep->data : 0 );
}
void
HASHinsert( Hash_TableP t, char * s, void * data ) {
SCL_HASHinsert( Hash_TableP t, char * s, void * data ) {
struct Element e, *e2;
e.key = s;
e.data = data;
e.symbol = 0;
e2 = HASHsearch( t, &e, HASH_INSERT );
e2 = SCL_HASHsearch( t, &e, HASH_INSERT );
if( e2 ) {
printf( "Redeclaration of %s\n", s );
}
}
Hash_TableP
HASHcreate( unsigned count ) {
SCL_HASHcreate( unsigned count ) {
unsigned int i;
Hash_TableP table;
@@ -101,7 +101,7 @@ HASHcreate( unsigned count ) {
}
count = DIV( i, SEGMENT_SIZE );
table = ( Hash_TableP ) HASH_Table_new();
table = ( Hash_TableP ) SCL_HASH_Table_new();
table->SegmentCount = table->p = table->KeyCount = 0;
/*
** First initialize directory to 0\'s
@@ -141,7 +141,7 @@ HASHcreate( unsigned count ) {
/* initialize pointer to beginning of hash table so we can step through it */
/* on repeated calls to HASHlist - DEL */
void
HASHlistinit( Hash_TableP table, HashEntry * he ) {
SCL_HASHlistinit( Hash_TableP table, HashEntry * he ) {
he->i = he->j = 0;
he->p = 0;
he->table = table;
@@ -150,7 +150,7 @@ HASHlistinit( Hash_TableP table, HashEntry * he ) {
}
void
HASHlistinit_by_type( Hash_TableP table, HashEntry * he, char type ) {
SCL_HASHlistinit_by_type( Hash_TableP table, HashEntry * he, char type ) {
he->i = he->j = 0;
he->p = 0;
he->table = table;
@@ -160,7 +160,7 @@ HASHlistinit_by_type( Hash_TableP table, HashEntry * he, char type ) {
/* provide a way to step through the hash */
struct Element *
HASHlist( HashEntry * he ) {
SCL_HASHlist( HashEntry * he ) {
int i2 = he->i;
int j2 = he->j;
struct Element ** s;
@@ -194,6 +194,9 @@ HASHlist( HashEntry * he ) {
again = false;
}
}
else {
again = false;
}
} while( again );
/* avoid incrementing he->j by returning here */
if( he->p ) {
@@ -208,7 +211,7 @@ HASHlist( HashEntry * he ) {
}
void
HASHdestroy( Hash_TableP table ) {
SCL_HASHdestroy( Hash_TableP table ) {
unsigned int i, j;
struct Element ** s;
struct Element * p, *q;
@@ -221,7 +224,7 @@ HASHdestroy( Hash_TableP table ) {
p = s[j];
while( p != NULL ) {
q = p->next;
HASH_Element_destroy( p );
SCL_HASH_Element_destroy( p );
p = q;
}
}
@@ -229,7 +232,7 @@ HASHdestroy( Hash_TableP table ) {
delete [] table->Directory[i];
}
}
HASH_Table_destroy( table );
SCL_HASH_Table_destroy( table );
# if HASH_STATISTICS && DEBUG
fprintf( stderr,
"[hdestroy] Accesses %ld Collisions %ld\n",
@@ -240,7 +243,7 @@ HASHdestroy( Hash_TableP table ) {
}
struct Element *
HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
SCL_HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
Address h;
struct Element ** CurrentSegment;
int SegmentIndex;
@@ -252,7 +255,7 @@ HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
# if HASH_STATISTICS
HashAccesses++;
# endif
h = HASHhash( item->key, table );
h = SCL_HASHhash( item->key, table );
SegmentDir = ( int ) DIV( h, SEGMENT_SIZE );
SegmentIndex = ( int ) MOD( h, SEGMENT_SIZE );
/*
@@ -286,7 +289,7 @@ HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
deleteme = q;
*p = q->next;
/*STRINGfree(deleteme->key);*/
HASH_Element_destroy( deleteme );
SCL_HASH_Element_destroy( deleteme );
--table->KeyCount;
return( deleteme ); /* of course, user shouldn't deref this! */
case HASH_INSERT:
@@ -296,7 +299,7 @@ HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
}
/* at this point, element does not exist and action == INSERT */
q = ( ElementP ) HASH_Element_new();
q = ( ElementP ) SCL_HASH_Element_new();
*p = q; /* link into chain */
/*
** Initialize new element
@@ -312,7 +315,7 @@ HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
** table over-full?
*/
if( ++table->KeyCount / MUL( table->SegmentCount, SEGMENT_SIZE ) > table->MaxLoadFactor ) {
HASHexpand_table( table ); /* doesn't affect q */
SCL_HASHexpand_table( table ); /* doesn't affect q */
}
}
return( ( struct Element * )0 ); /* was return (Element)q */
@@ -323,7 +326,7 @@ HASHsearch( Hash_TableP table, const struct Element * item, Action action ) {
*/
Address
HASHhash( char * Key, Hash_TableP table ) {
SCL_HASHhash( char * Key, Hash_TableP table ) {
Address h, address;
register unsigned char * k = ( unsigned char * )Key;
@@ -344,7 +347,7 @@ HASHhash( char * Key, Hash_TableP table ) {
static
void
HASHexpand_table( Hash_TableP table ) {
SCL_HASHexpand_table( Hash_TableP table ) {
Address NewAddress;
int OldSegmentIndex, NewSegmentIndex;
int OldSegmentDir, NewSegmentDir;
@@ -389,7 +392,7 @@ HASHexpand_table( Hash_TableP table ) {
LastOfNew = &NewSegment[NewSegmentIndex];
*LastOfNew = NULL;
while( Current != NULL ) {
if( HASHhash( Current->key, table ) == NewAddress ) {
if( SCL_HASHhash( Current->key, table ) == NewAddress ) {
/*
** Attach it to the end of the new chain
*/
+9 -9
View File
@@ -132,15 +132,15 @@ typedef struct {
extern "C" {
#endif
SCL_UTILS_EXPORT struct Hash_Table * HASHcreate( unsigned );
SCL_UTILS_EXPORT void HASHinitialize( void );
SCL_UTILS_EXPORT void * HASHfind( struct Hash_Table *, char * );
SCL_UTILS_EXPORT void HASHinsert( struct Hash_Table *, char *, void * );
SCL_UTILS_EXPORT void HASHdestroy( struct Hash_Table * );
SCL_UTILS_EXPORT struct Element * HASHsearch( struct Hash_Table *, const struct Element *, Action );
SCL_UTILS_EXPORT void HASHlistinit( struct Hash_Table *, HashEntry * );
SCL_UTILS_EXPORT void HASHlistinit_by_type( struct Hash_Table *, HashEntry *, char );
SCL_UTILS_EXPORT struct Element * HASHlist( HashEntry * );
SCL_UTILS_EXPORT struct Hash_Table * SCL_HASHcreate( unsigned );
SCL_UTILS_EXPORT void SCL_HASHinitialize( void );
SCL_UTILS_EXPORT void * SCL_HASHfind( struct Hash_Table *, char * );
SCL_UTILS_EXPORT void SCL_HASHinsert( struct Hash_Table *, char *, void * );
SCL_UTILS_EXPORT void SCL_HASHdestroy( struct Hash_Table * );
SCL_UTILS_EXPORT struct Element * SCL_HASHsearch( struct Hash_Table *, const struct Element *, Action );
SCL_UTILS_EXPORT void SCL_HASHlistinit( struct Hash_Table *, HashEntry * );
SCL_UTILS_EXPORT void SCL_HASHlistinit_by_type( struct Hash_Table *, HashEntry *, char );
SCL_UTILS_EXPORT struct Element * SCL_HASHlist( HashEntry * );
#ifdef __cplusplus
}