diff --git a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj index 2f904ac..f7a110a 100755 --- a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj +++ b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj @@ -54,7 +54,7 @@ 2255754917551234009946B1 /* report.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7E1068369500641384 /* report.c */; }; 2255754A17551234009946B1 /* rules.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7F1068369500641384 /* rules.c */; }; 2255754B17551234009946B1 /* smatrix.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F801068369500641384 /* smatrix.c */; }; - 226537E0179EDEEB00258C60 /* epanet2.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322FA9106836B000641384 /* epanet2.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 226537E0179EDEEB00258C60 /* epanet2.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322FA9106836B000641384 /* epanet2.h */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -484,6 +484,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Debug; }; @@ -503,6 +504,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Release; }; diff --git a/src/epanet.c b/src/epanet.c index 96b87a3..ba67420 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -96,9 +96,9 @@ This module calls the following functions that reside in other modules: writelogo() writereport() HASH.C - HTcreate() - HTfind() - HTfree() + ENHashTablecreate() + ENHashTableFind() + ENHashTableFree() The macro ERRCODE(x) is defined in TYPES.H. It says if the current value of the error code variable (errcode) is not fatal (< 100) then @@ -2802,8 +2802,8 @@ void initpointers() XLNZ = NULL; NZSUB = NULL; LNZ = NULL; - Nht = NULL; - Lht = NULL; + NodeHashTable = NULL; + LinkHashTable = NULL; initrules(); } @@ -2821,10 +2821,10 @@ int allocdata() int errcode = 0; /* Allocate node & link ID hash tables */ - Nht = HTcreate(); - Lht = HTcreate(); - ERRCODE(MEMCHECK(Nht)); - ERRCODE(MEMCHECK(Lht)); + NodeHashTable = ENHashTableCreate(); + LinkHashTable = ENHashTableCreate(); + ERRCODE(MEMCHECK(NodeHashTable)); + ERRCODE(MEMCHECK(LinkHashTable)); /* Allocate memory for network nodes */ /************************************************************* @@ -3023,8 +3023,8 @@ void freedata() freerules(); /* Free hash table memory */ - if (Nht != NULL) HTfree(Nht); - if (Lht != NULL) HTfree(Lht); + if (NodeHashTable != NULL) ENHashTableFree(NodeHashTable); + if (LinkHashTable != NULL) ENHashTableFree(LinkHashTable); } @@ -3138,7 +3138,7 @@ int findnode(char *id) **---------------------------------------------------------------- */ { - return(HTfind(Nht,id)); + return(ENHashTableFind(NodeHashTable,id)); } @@ -3151,7 +3151,7 @@ int findlink(char *id) **---------------------------------------------------------------- */ { - return(HTfind(Lht,id)); + return(ENHashTableFind(LinkHashTable,id)); } diff --git a/src/hash.c b/src/hash.c index 64af9a7..26c07bf 100755 --- a/src/hash.c +++ b/src/hash.c @@ -1,22 +1,22 @@ /*----------------------------------------------------------------------------- -** hash.c -** -** Implementation of a simple Hash Table for string storage & retrieval -** -** Written by L. Rossman -** Last Updated on 6/19/03 -** -** The hash table data structure (HTable) is defined in "hash.h". -** Interface Functions: -** HTcreate() - creates a hash table -** HTinsert() - inserts a string & its index value into a hash table -** HTfind() - retrieves the index value of a string from a table -** HTfree() - frees a hash table -** -********************************************************************* -** NOTE: This is a modified version of the original HASH.C module. -********************************************************************* -*/ + ** hash.c + ** + ** Implementation of a simple Hash Table for string storage & retrieval + ** + ** Written by L. Rossman + ** Last Updated on 6/19/03 + ** + ** The hash table data structure (HTable) is defined in "hash.h". + ** Interface Functions: + ** HTcreate() - creates a hash table + ** HTinsert() - inserts a string & its index value into a hash table + ** HTfind() - retrieves the index value of a string from a table + ** HTfree() - frees a hash table + ** + ********************************************************************* + ** NOTE: This is a modified version of the original HASH.C module. + ********************************************************************* + */ #ifndef __APPLE__ #include @@ -26,89 +26,97 @@ #include #include "hash.h" -/* Use Fletcher's checksum to compute 2-byte hash of string */ -unsigned int hash(char *str) +unsigned int _enHash(char *str); +unsigned int _enHash(char *str) { - unsigned int sum1= 0, check1; - unsigned long sum2= 0L; - while( '\0' != *str ) - { - sum1 += (*str); - str++; - if ( 255 <= sum1 ) sum1 -= 255; - sum2 += sum1; + unsigned int hash = 5381; + int c; + while ((c = *str++)) { + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + } + unsigned int retHash = hash % ENHASHTABLEMAXSIZE; + return retHash; +} + +ENHashTable *ENHashTableCreate() +{ + int i; + ENHashTable *ht = (ENHashTable *) calloc(ENHASHTABLEMAXSIZE, sizeof(ENHashTable)); + if (ht != NULL) { + for (i=0; i= ENHASHTABLEMAXSIZE ) { + return(0); + } + entry = (ENHashEntry *) malloc(sizeof(ENHashEntry)); + if (entry == NULL) { + return(0); + } + entry->key = key; + entry->data = data; + entry->next = ht[i]; + ht[i] = entry; + return(1); } -int HTinsert(HTtable *ht, char *key, int data) +int ENHashTableFind(ENHashTable *ht, char *key) { - unsigned int i = hash(key); - struct HTentry *entry; - if ( i >= HTMAXSIZE ) return(0); - entry = (struct HTentry *) malloc(sizeof(struct HTentry)); - if (entry == NULL) return(0); - entry->key = key; - entry->data = data; - entry->next = ht[i]; - ht[i] = entry; - return(1); + unsigned int i = _enHash(key); + ENHashEntry *entry; + if ( i >= ENHASHTABLEMAXSIZE ) { + return(NOTFOUND); + } + entry = ht[i]; + while (entry != NULL) + { + if ( strcmp(entry->key,key) == 0 ) { + return(entry->data); + } + entry = entry->next; + } + return(NOTFOUND); } -int HTfind(HTtable *ht, char *key) +char *ENHashTableFindKey(ENHashTable *ht, char *key) { - unsigned int i = hash(key); - struct HTentry *entry; - if ( i >= HTMAXSIZE ) return(NOTFOUND); - entry = ht[i]; - while (entry != NULL) - { - if ( strcmp(entry->key,key) == 0 ) return(entry->data); - entry = entry->next; - } - return(NOTFOUND); + unsigned int i = _enHash(key); + ENHashEntry *entry; + if ( i >= ENHASHTABLEMAXSIZE ) { + return(NULL); + } + entry = ht[i]; + while (entry != NULL) + { + if ( strcmp(entry->key,key) == 0 ) { + return(entry->key); + } + entry = entry->next; + } + return(NULL); } -char *HTfindKey(HTtable *ht, char *key) +void ENHashTableFree(ENHashTable *ht) { - unsigned int i = hash(key); - struct HTentry *entry; - if ( i >= HTMAXSIZE ) return(NULL); - entry = ht[i]; - while (entry != NULL) - { - if ( strcmp(entry->key,key) == 0 ) return(entry->key); - entry = entry->next; - } - return(NULL); -} - -void HTfree(HTtable *ht) -{ - struct HTentry *entry, - *nextentry; - int i; - for (i=0; inext; - free(entry); - entry = nextentry; - } - } - free(ht); + ENHashEntry *entry, *nextentry; + int i; + for (i=0; inext; + free(entry); + entry = nextentry; + } + } + free(ht); } diff --git a/src/hash.h b/src/hash.h index 38999d1..2952ae6 100755 --- a/src/hash.h +++ b/src/hash.h @@ -7,22 +7,22 @@ #ifndef HASH_H #define HASH_H -#define HTMAXSIZE 1999 +#define ENHASHTABLEMAXSIZE 128000 #define NOTFOUND 0 -struct HTentry +typedef struct HTentryStruct { char *key; int data; - struct HTentry *next; -}; + struct HTentryStruct *next; +} ENHashEntry; -typedef struct HTentry *HTtable; +typedef ENHashEntry *ENHashTable; -HTtable *HTcreate(void); -int HTinsert(HTtable *, char *, int); -int HTfind(HTtable *, char *); -char *HTfindKey(HTtable *, char *); -void HTfree(HTtable *); +ENHashTable *ENHashTableCreate(void); +int ENHashTableInsert(ENHashTable *, char *, int); +int ENHashTableFind(ENHashTable *, char *); +char *ENHashTableFindKey(ENHashTable *, char *); +void ENHashTableFree(ENHashTable *); #endif \ No newline at end of file diff --git a/src/input2.c b/src/input2.c index 9f569e0..b372867 100755 --- a/src/input2.c +++ b/src/input2.c @@ -423,7 +423,7 @@ int addnodeID(int n, char *id) { if (findnode(id)) return(0); /* see EPANET.C */ strncpy(Node[n].ID, id, MAXID); - HTinsert(Nht, Node[n].ID, n); /* see HASH.C */ + ENHashTableInsert(NodeHashTable, Node[n].ID, n); /* see HASH.C */ return(1); } @@ -440,7 +440,7 @@ int addlinkID(int n, char *id) { if (findlink(id)) return(0); /* see EPANET.C */ strncpy(Link[n].ID, id, MAXID); - HTinsert(Lht, Link[n].ID, n); /* see HASH.C */ + ENHashTableInsert(LinkHashTable, Link[n].ID, n); /* see HASH.C */ return(1); } diff --git a/src/vars.h b/src/vars.h index 59b92ad..77b7284 100755 --- a/src/vars.h +++ b/src/vars.h @@ -169,7 +169,7 @@ EXTERN Stank *Tank; /* Tank data */ EXTERN Spump *Pump; /* Pump data */ EXTERN Svalve *Valve; /* Valve data */ EXTERN Scontrol *Control; /* Control data */ -EXTERN HTtable *Nht, *Lht; /* Hash tables for ID labels */ +EXTERN ENHashTable *NodeHashTable, *LinkHashTable; /* Hash tables for ID labels */ EXTERN Padjlist *Adjlist; /* Node adjacency lists */ EXTERN double _relativeError; EXTERN int _iterations; /* Info about hydraulic solution */