epyt-flow 0.14.1__py3-none-any.whl → 0.14.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- epyt_flow/EPANET/EPANET/SRC_engines/AUTHORS +8 -40
- epyt_flow/EPANET/EPANET/SRC_engines/LICENSE +3 -3
- epyt_flow/EPANET/EPANET/SRC_engines/Readme_SRC_Engines.txt +18 -0
- epyt_flow/EPANET/EPANET/SRC_engines/enumstxt.h +7 -24
- epyt_flow/EPANET/EPANET/SRC_engines/epanet.c +374 -726
- epyt_flow/EPANET/EPANET/SRC_engines/epanet2.c +32 -128
- epyt_flow/EPANET/EPANET/SRC_engines/epanet2.def +131 -0
- epyt_flow/EPANET/EPANET/SRC_engines/errors.dat +1 -7
- epyt_flow/EPANET/EPANET/SRC_engines/funcs.h +14 -40
- epyt_flow/EPANET/EPANET/SRC_engines/hash.c +177 -177
- epyt_flow/EPANET/EPANET/SRC_engines/hash.h +28 -28
- epyt_flow/EPANET/EPANET/SRC_engines/hydcoeffs.c +40 -192
- epyt_flow/EPANET/EPANET/SRC_engines/hydraul.c +46 -101
- epyt_flow/EPANET/EPANET/SRC_engines/hydsolver.c +24 -85
- epyt_flow/EPANET/EPANET/SRC_engines/hydstatus.c +63 -29
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2.h +37 -70
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_2.h +234 -408
- epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_enums.h +37 -87
- epyt_flow/EPANET/EPANET/SRC_engines/inpfile.c +79 -153
- epyt_flow/EPANET/EPANET/SRC_engines/input1.c +94 -59
- epyt_flow/EPANET/EPANET/SRC_engines/input2.c +202 -73
- epyt_flow/EPANET/EPANET/SRC_engines/input3.c +351 -446
- epyt_flow/EPANET/EPANET/SRC_engines/main.c +93 -0
- epyt_flow/EPANET/EPANET/SRC_engines/mempool.c +4 -8
- epyt_flow/EPANET/EPANET/SRC_engines/mempool.h +23 -23
- epyt_flow/EPANET/EPANET/SRC_engines/output.c +4 -5
- epyt_flow/EPANET/EPANET/SRC_engines/project.c +75 -407
- epyt_flow/EPANET/EPANET/SRC_engines/quality.c +2 -12
- epyt_flow/EPANET/EPANET/SRC_engines/qualreact.c +13 -70
- epyt_flow/EPANET/EPANET/SRC_engines/qualroute.c +5 -7
- epyt_flow/EPANET/EPANET/SRC_engines/report.c +20 -88
- epyt_flow/EPANET/EPANET/SRC_engines/rules.c +6 -144
- epyt_flow/EPANET/EPANET/SRC_engines/smatrix.c +19 -19
- epyt_flow/EPANET/EPANET/SRC_engines/text.h +5 -16
- epyt_flow/EPANET/EPANET/SRC_engines/types.h +19 -73
- epyt_flow/EPANET/compile_linux.sh +1 -1
- epyt_flow/EPANET/compile_macos.sh +1 -1
- epyt_flow/VERSION +1 -1
- epyt_flow/simulation/scada/scada_data.py +1 -1
- epyt_flow/utils.py +66 -0
- epyt_flow/visualization/visualization_utils.py +4 -2
- {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/METADATA +1 -1
- {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/RECORD +46 -52
- epyt_flow/EPANET/EPANET/SRC_engines/flowbalance.c +0 -186
- epyt_flow/EPANET/EPANET/SRC_engines/leakage.c +0 -527
- epyt_flow/EPANET/EPANET/SRC_engines/util/cstr_helper.c +0 -59
- epyt_flow/EPANET/EPANET/SRC_engines/util/cstr_helper.h +0 -38
- epyt_flow/EPANET/EPANET/SRC_engines/util/errormanager.c +0 -92
- epyt_flow/EPANET/EPANET/SRC_engines/util/errormanager.h +0 -39
- epyt_flow/EPANET/EPANET/SRC_engines/util/filemanager.c +0 -212
- epyt_flow/EPANET/EPANET/SRC_engines/util/filemanager.h +0 -81
- epyt_flow/EPANET/EPANET/SRC_engines/validate.c +0 -408
- {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/WHEEL +0 -0
- {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/licenses/LICENSE +0 -0
- {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/top_level.txt +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
2
|
******************************************************************************
|
|
3
3
|
Project: OWA EPANET
|
|
4
|
-
Version: 2.
|
|
4
|
+
Version: 2.2
|
|
5
5
|
Module: funcs.h
|
|
6
6
|
Description: prototypes of external functions called by various modules
|
|
7
7
|
Authors: see AUTHORS
|
|
8
8
|
Copyright: see AUTHORS
|
|
9
9
|
License: see LICENSE
|
|
10
|
-
Last Updated:
|
|
10
|
+
Last Updated: 11/15/2019
|
|
11
11
|
******************************************************************************
|
|
12
12
|
*/
|
|
13
13
|
#ifndef FUNCS_H
|
|
@@ -19,7 +19,6 @@ void initpointers(Project *);
|
|
|
19
19
|
int allocdata(Project *);
|
|
20
20
|
void freedata(Project *);
|
|
21
21
|
|
|
22
|
-
int openproject(Project *, const char *, const char *, const char *, int);
|
|
23
22
|
int openfiles(Project *, const char *, const char *,const char *);
|
|
24
23
|
int openhydfile(Project *);
|
|
25
24
|
int openoutfile(Project *);
|
|
@@ -29,20 +28,17 @@ int buildadjlists(Network *);
|
|
|
29
28
|
void freeadjlists(Network *);
|
|
30
29
|
|
|
31
30
|
int incontrols(Project *, int, int);
|
|
32
|
-
int changevalvetype(Project *, int, int);
|
|
33
31
|
int valvecheck(Project *, int, int, int, int);
|
|
34
|
-
int
|
|
35
|
-
|
|
36
|
-
int findnode(Network *, const char *);
|
|
37
|
-
int findlink(Network *, const char *);
|
|
32
|
+
int findnode(Network *, char *);
|
|
33
|
+
int findlink(Network *, char *);
|
|
38
34
|
int findtank(Network *, int);
|
|
39
35
|
int findvalve(Network *, int);
|
|
40
36
|
int findpump(Network *, int);
|
|
41
|
-
int findpattern(Network *,
|
|
42
|
-
int findcurve(Network *,
|
|
37
|
+
int findpattern(Network *, char *);
|
|
38
|
+
int findcurve(Network *, char *);
|
|
43
39
|
|
|
44
40
|
Pdemand finddemand(Pdemand, int);
|
|
45
|
-
int adddemand(Snode *, double, int,
|
|
41
|
+
int adddemand(Snode *, double, int, char *);
|
|
46
42
|
void freedemands(Snode *);
|
|
47
43
|
|
|
48
44
|
int addlinkvertex(Slink *, double, double);
|
|
@@ -50,13 +46,11 @@ void freelinkvertices(Slink *);
|
|
|
50
46
|
|
|
51
47
|
void adjustpatterns(Network *, int);
|
|
52
48
|
void adjustcurves(Network *, int);
|
|
49
|
+
int adjustpumpparams(Project *, int);
|
|
53
50
|
int resizecurve(Scurve *, int);
|
|
54
|
-
int setcontrol(Project *, int, int, double, int, double, Scontrol *);
|
|
55
51
|
|
|
56
52
|
int getcomment(Network *, int, int, char *);
|
|
57
53
|
int setcomment(Network *, int, int, const char *);
|
|
58
|
-
int gettag(Network *, int, int, char *);
|
|
59
|
-
int settag(Network *, int, int, const char *);
|
|
60
54
|
|
|
61
55
|
int namevalid(const char *);
|
|
62
56
|
void getTmpName(char *);
|
|
@@ -73,7 +67,7 @@ int getdata(Project *);
|
|
|
73
67
|
void setdefaults(Project *);
|
|
74
68
|
void initreport(Report *);
|
|
75
69
|
void adjustdata(Project *);
|
|
76
|
-
|
|
70
|
+
int inittanks(Project *);
|
|
77
71
|
void initunits(Project *);
|
|
78
72
|
void convertunits(Project *);
|
|
79
73
|
|
|
@@ -81,6 +75,7 @@ void convertunits(Project *);
|
|
|
81
75
|
|
|
82
76
|
int netsize(Project *);
|
|
83
77
|
int readdata(Project *);
|
|
78
|
+
int updatepumpparams(Project *, int);
|
|
84
79
|
int findmatch(char *, char *[]);
|
|
85
80
|
int match(const char *, const char *);
|
|
86
81
|
int gettokens(char *, char **, int, char *);
|
|
@@ -103,7 +98,6 @@ int controldata(Project *);
|
|
|
103
98
|
int energydata(Project *);
|
|
104
99
|
int sourcedata(Project *);
|
|
105
100
|
int emitterdata(Project *);
|
|
106
|
-
int leakagedata(Project *);
|
|
107
101
|
int qualdata(Project *);
|
|
108
102
|
int reactdata(Project *);
|
|
109
103
|
int mixingdata(Project *);
|
|
@@ -112,7 +106,6 @@ int reportdata(Project *);
|
|
|
112
106
|
int timedata(Project *);
|
|
113
107
|
int optiondata(Project *);
|
|
114
108
|
int vertexdata(Project *);
|
|
115
|
-
int tagdata(Project *);
|
|
116
109
|
|
|
117
110
|
// ------- RULES.C ------------------
|
|
118
111
|
|
|
@@ -124,30 +117,28 @@ void freerules(Project *);
|
|
|
124
117
|
int ruledata(Project *);
|
|
125
118
|
void ruleerrmsg(Project *);
|
|
126
119
|
void adjustrules(Project *, int, int);
|
|
127
|
-
void adjusttankrules(Project
|
|
120
|
+
void adjusttankrules(Project *);
|
|
128
121
|
Spremise *getpremise(Spremise *, int);
|
|
129
122
|
Saction *getaction(Saction *, int);
|
|
130
123
|
int writerule(Project *, FILE *, int);
|
|
131
124
|
int checkrules(Project *, long);
|
|
132
|
-
void updateruleunits(Project *pr, double dcf, double pcf, double hcf, double qcf);
|
|
133
125
|
|
|
134
126
|
// ------- REPORT.C -----------------
|
|
135
127
|
|
|
136
128
|
int clearreport(Project *);
|
|
137
|
-
int copyreport(Project *,
|
|
129
|
+
int copyreport(Project *, char *);
|
|
138
130
|
int writereport(Project *);
|
|
139
131
|
void writelogo(Project *);
|
|
140
132
|
void writesummary(Project *);
|
|
141
133
|
void writehydstat(Project *, int, double);
|
|
142
134
|
void writeheader(Project *, int,int);
|
|
143
|
-
void writeline(Project *,
|
|
135
|
+
void writeline(Project *, char *);
|
|
144
136
|
void writerelerr(Project *, int, double);
|
|
145
137
|
void writestatchange(Project *, int,char,char);
|
|
146
138
|
void writecontrolaction(Project *, int, int);
|
|
147
139
|
void writeruleaction(Project *, int, char *);
|
|
148
140
|
int writehydwarn(Project *, int,double);
|
|
149
141
|
void writehyderr(Project *, int);
|
|
150
|
-
void writeflowbalance(Project *);
|
|
151
142
|
void writemassbalance(Project *);
|
|
152
143
|
void writetime(Project *, char *);
|
|
153
144
|
char *clocktime(char *, long);
|
|
@@ -162,7 +153,6 @@ void closehyd(Project *);
|
|
|
162
153
|
void setlinkstatus(Project *, int, char, StatusType *, double *);
|
|
163
154
|
void setlinksetting(Project *, int, double, StatusType *, double *);
|
|
164
155
|
int tanktimestep(Project *, long *);
|
|
165
|
-
int controltimestep(Project *, long *);
|
|
166
156
|
void getenergy(Project *, int, double *, double *);
|
|
167
157
|
double tankvolume(Project *, int, double);
|
|
168
158
|
double tankgrade(Project *, int, double);
|
|
@@ -172,9 +162,8 @@ double tankgrade(Project *, int, double);
|
|
|
172
162
|
void resistcoeff(Project *, int);
|
|
173
163
|
void headlosscoeffs(Project *);
|
|
174
164
|
void matrixcoeffs(Project *);
|
|
175
|
-
void emitterheadloss(Project *, int, double *, double *);
|
|
165
|
+
void emitterheadloss(Project *, int, double *, double *);
|
|
176
166
|
void demandheadloss(Project *, int, double, double, double *, double *);
|
|
177
|
-
double pcvlosscoeff(Project *, int, double);
|
|
178
167
|
|
|
179
168
|
// ------- QUALITY.C --------------------
|
|
180
169
|
|
|
@@ -201,19 +190,4 @@ int savefinaloutput(Project *);
|
|
|
201
190
|
|
|
202
191
|
int saveinpfile(Project *, const char *);
|
|
203
192
|
|
|
204
|
-
// ------- LEAKAGE.C --------------------
|
|
205
|
-
|
|
206
|
-
int openleakage(Project *);
|
|
207
|
-
void closeleakage(Project *);
|
|
208
|
-
double findlinkleakage(Project *, int);
|
|
209
|
-
void leakagecoeffs(Project *);
|
|
210
|
-
double leakageflowchange(Project *, int);
|
|
211
|
-
int leakagehasconverged(Project *);
|
|
212
|
-
|
|
213
|
-
// ------- FLOWBALANCE.C-----------------
|
|
214
|
-
|
|
215
|
-
void startflowbalance(Project *);
|
|
216
|
-
void updateflowbalance(Project *, long);
|
|
217
|
-
void endflowbalance(Project *);
|
|
218
|
-
|
|
219
193
|
#endif
|
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
/*
|
|
2
|
-
******************************************************************************
|
|
3
|
-
Project: OWA EPANET
|
|
4
|
-
Version: 2.
|
|
5
|
-
Module: hash.c
|
|
6
|
-
Description: implementation of a simple hash table
|
|
7
|
-
Authors: see AUTHORS
|
|
8
|
-
Copyright: see AUTHORS
|
|
9
|
-
License: see LICENSE
|
|
10
|
-
Last Updated: 05/15/2019
|
|
11
|
-
******************************************************************************
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
#include <stdlib.h>
|
|
15
|
-
#include <string.h>
|
|
16
|
-
#include "hash.h"
|
|
17
|
-
|
|
18
|
-
#define HASHTABLEMAXSIZE 128000
|
|
19
|
-
|
|
20
|
-
// An entry in the hash table
|
|
21
|
-
typedef struct DataEntryStruct
|
|
22
|
-
{
|
|
23
|
-
char *key;
|
|
24
|
-
int data;
|
|
25
|
-
struct DataEntryStruct *next;
|
|
26
|
-
} DataEntry;
|
|
27
|
-
|
|
28
|
-
// Hash a string to an integer
|
|
29
|
-
unsigned int gethash(
|
|
30
|
-
{
|
|
31
|
-
unsigned int hash = 5381;
|
|
32
|
-
unsigned int retHash;
|
|
33
|
-
int c;
|
|
34
|
-
while ((c = *str++))
|
|
35
|
-
{
|
|
36
|
-
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
|
37
|
-
}
|
|
38
|
-
retHash = hash % HASHTABLEMAXSIZE;
|
|
39
|
-
return retHash;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Produce a duplicate string
|
|
43
|
-
char *dupstr(const char *s)
|
|
44
|
-
{
|
|
45
|
-
size_t size = strlen(s) + 1;
|
|
46
|
-
char *p = malloc(size);
|
|
47
|
-
if (p) memcpy(p, s, size);
|
|
48
|
-
return p;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Create a hash table
|
|
52
|
-
HashTable *hashtable_create()
|
|
53
|
-
{
|
|
54
|
-
int i;
|
|
55
|
-
HashTable *ht = (HashTable *) calloc(HASHTABLEMAXSIZE, sizeof(HashTable));
|
|
56
|
-
if (ht != NULL)
|
|
57
|
-
{
|
|
58
|
-
for (i = 0; i < HASHTABLEMAXSIZE; i++) ht[i] = NULL;
|
|
59
|
-
}
|
|
60
|
-
return ht;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Insert an entry into the hash table
|
|
64
|
-
int hashtable_insert(HashTable *ht,
|
|
65
|
-
{
|
|
66
|
-
unsigned int i = gethash(key);
|
|
67
|
-
DataEntry *entry;
|
|
68
|
-
if ( i >= HASHTABLEMAXSIZE ) return 0;
|
|
69
|
-
entry = (DataEntry *) malloc(sizeof(DataEntry));
|
|
70
|
-
if (entry == NULL) return(0);
|
|
71
|
-
entry->key = dupstr(key);
|
|
72
|
-
entry->data = data;
|
|
73
|
-
entry->next = ht[i];
|
|
74
|
-
ht[i] = entry;
|
|
75
|
-
return 1;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Change the hash table's data entry for a particular key
|
|
79
|
-
int hashtable_update(HashTable *ht,
|
|
80
|
-
{
|
|
81
|
-
unsigned int i = gethash(key);
|
|
82
|
-
DataEntry *entry;
|
|
83
|
-
|
|
84
|
-
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
85
|
-
entry = ht[i];
|
|
86
|
-
while (entry != NULL)
|
|
87
|
-
{
|
|
88
|
-
if ( strcmp(entry->key, key) == 0 )
|
|
89
|
-
{
|
|
90
|
-
entry->data = new_data;
|
|
91
|
-
return 1;
|
|
92
|
-
}
|
|
93
|
-
entry = entry->next;
|
|
94
|
-
}
|
|
95
|
-
return NOTFOUND;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Delete an entry in the hash table
|
|
99
|
-
int hashtable_delete(HashTable *ht,
|
|
100
|
-
{
|
|
101
|
-
unsigned int i = gethash(key);
|
|
102
|
-
DataEntry *entry, *preventry;
|
|
103
|
-
|
|
104
|
-
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
105
|
-
|
|
106
|
-
preventry = NULL;
|
|
107
|
-
entry = ht[i];
|
|
108
|
-
while (entry != NULL)
|
|
109
|
-
{
|
|
110
|
-
if (strcmp(entry->key, key) == 0)
|
|
111
|
-
{
|
|
112
|
-
if (preventry == NULL) ht[i] = entry->next;
|
|
113
|
-
else preventry->next = entry->next;
|
|
114
|
-
free(entry->key);
|
|
115
|
-
free(entry);
|
|
116
|
-
return 1;
|
|
117
|
-
}
|
|
118
|
-
preventry = entry;
|
|
119
|
-
entry = entry->next;
|
|
120
|
-
}
|
|
121
|
-
return NOTFOUND;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Find the data for a particular key
|
|
125
|
-
int hashtable_find(HashTable *ht,
|
|
126
|
-
{
|
|
127
|
-
unsigned int i = gethash(key);
|
|
128
|
-
DataEntry *entry;
|
|
129
|
-
|
|
130
|
-
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
131
|
-
entry = ht[i];
|
|
132
|
-
while (entry != NULL)
|
|
133
|
-
{
|
|
134
|
-
if ( strcmp(entry->key, key) == 0 )
|
|
135
|
-
{
|
|
136
|
-
return entry->data;
|
|
137
|
-
}
|
|
138
|
-
entry = entry->next;
|
|
139
|
-
}
|
|
140
|
-
return NOTFOUND;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Find a particular key in the hash table
|
|
144
|
-
char *hashtable_findkey(HashTable *ht,
|
|
145
|
-
{
|
|
146
|
-
unsigned int i = gethash(key);
|
|
147
|
-
DataEntry *entry;
|
|
148
|
-
if ( i >= HASHTABLEMAXSIZE ) return NULL;
|
|
149
|
-
entry = ht[i];
|
|
150
|
-
while (entry != NULL)
|
|
151
|
-
{
|
|
152
|
-
if ( strcmp(entry->key, key) == 0 ) return entry->key;
|
|
153
|
-
entry = entry->next;
|
|
154
|
-
}
|
|
155
|
-
return NULL;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Delete a hash table and free all of its memory
|
|
159
|
-
void hashtable_free(HashTable *ht)
|
|
160
|
-
{
|
|
161
|
-
DataEntry *entry, *nextentry;
|
|
162
|
-
int i;
|
|
163
|
-
|
|
164
|
-
for (i = 0; i < HASHTABLEMAXSIZE; i++)
|
|
165
|
-
{
|
|
166
|
-
entry = ht[i];
|
|
167
|
-
while (entry != NULL)
|
|
168
|
-
{
|
|
169
|
-
nextentry = entry->next;
|
|
170
|
-
free(entry->key);
|
|
171
|
-
free(entry);
|
|
172
|
-
entry = nextentry;
|
|
173
|
-
}
|
|
174
|
-
ht[i] = NULL;
|
|
175
|
-
}
|
|
176
|
-
free(ht);
|
|
177
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.2
|
|
5
|
+
Module: hash.c
|
|
6
|
+
Description: implementation of a simple hash table
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 05/15/2019
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
#include "hash.h"
|
|
17
|
+
|
|
18
|
+
#define HASHTABLEMAXSIZE 128000
|
|
19
|
+
|
|
20
|
+
// An entry in the hash table
|
|
21
|
+
typedef struct DataEntryStruct
|
|
22
|
+
{
|
|
23
|
+
char *key;
|
|
24
|
+
int data;
|
|
25
|
+
struct DataEntryStruct *next;
|
|
26
|
+
} DataEntry;
|
|
27
|
+
|
|
28
|
+
// Hash a string to an integer
|
|
29
|
+
unsigned int gethash(char *str)
|
|
30
|
+
{
|
|
31
|
+
unsigned int hash = 5381;
|
|
32
|
+
unsigned int retHash;
|
|
33
|
+
int c;
|
|
34
|
+
while ((c = *str++))
|
|
35
|
+
{
|
|
36
|
+
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
|
37
|
+
}
|
|
38
|
+
retHash = hash % HASHTABLEMAXSIZE;
|
|
39
|
+
return retHash;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Produce a duplicate string
|
|
43
|
+
char *dupstr(const char *s)
|
|
44
|
+
{
|
|
45
|
+
size_t size = strlen(s) + 1;
|
|
46
|
+
char *p = malloc(size);
|
|
47
|
+
if (p) memcpy(p, s, size);
|
|
48
|
+
return p;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Create a hash table
|
|
52
|
+
HashTable *hashtable_create()
|
|
53
|
+
{
|
|
54
|
+
int i;
|
|
55
|
+
HashTable *ht = (HashTable *) calloc(HASHTABLEMAXSIZE, sizeof(HashTable));
|
|
56
|
+
if (ht != NULL)
|
|
57
|
+
{
|
|
58
|
+
for (i = 0; i < HASHTABLEMAXSIZE; i++) ht[i] = NULL;
|
|
59
|
+
}
|
|
60
|
+
return ht;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Insert an entry into the hash table
|
|
64
|
+
int hashtable_insert(HashTable *ht, char *key, int data)
|
|
65
|
+
{
|
|
66
|
+
unsigned int i = gethash(key);
|
|
67
|
+
DataEntry *entry;
|
|
68
|
+
if ( i >= HASHTABLEMAXSIZE ) return 0;
|
|
69
|
+
entry = (DataEntry *) malloc(sizeof(DataEntry));
|
|
70
|
+
if (entry == NULL) return(0);
|
|
71
|
+
entry->key = dupstr(key);
|
|
72
|
+
entry->data = data;
|
|
73
|
+
entry->next = ht[i];
|
|
74
|
+
ht[i] = entry;
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Change the hash table's data entry for a particular key
|
|
79
|
+
int hashtable_update(HashTable *ht, char *key, int new_data)
|
|
80
|
+
{
|
|
81
|
+
unsigned int i = gethash(key);
|
|
82
|
+
DataEntry *entry;
|
|
83
|
+
|
|
84
|
+
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
85
|
+
entry = ht[i];
|
|
86
|
+
while (entry != NULL)
|
|
87
|
+
{
|
|
88
|
+
if ( strcmp(entry->key, key) == 0 )
|
|
89
|
+
{
|
|
90
|
+
entry->data = new_data;
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
entry = entry->next;
|
|
94
|
+
}
|
|
95
|
+
return NOTFOUND;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Delete an entry in the hash table
|
|
99
|
+
int hashtable_delete(HashTable *ht, char *key)
|
|
100
|
+
{
|
|
101
|
+
unsigned int i = gethash(key);
|
|
102
|
+
DataEntry *entry, *preventry;
|
|
103
|
+
|
|
104
|
+
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
105
|
+
|
|
106
|
+
preventry = NULL;
|
|
107
|
+
entry = ht[i];
|
|
108
|
+
while (entry != NULL)
|
|
109
|
+
{
|
|
110
|
+
if (strcmp(entry->key, key) == 0)
|
|
111
|
+
{
|
|
112
|
+
if (preventry == NULL) ht[i] = entry->next;
|
|
113
|
+
else preventry->next = entry->next;
|
|
114
|
+
free(entry->key);
|
|
115
|
+
free(entry);
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
preventry = entry;
|
|
119
|
+
entry = entry->next;
|
|
120
|
+
}
|
|
121
|
+
return NOTFOUND;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Find the data for a particular key
|
|
125
|
+
int hashtable_find(HashTable *ht, char *key)
|
|
126
|
+
{
|
|
127
|
+
unsigned int i = gethash(key);
|
|
128
|
+
DataEntry *entry;
|
|
129
|
+
|
|
130
|
+
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
|
131
|
+
entry = ht[i];
|
|
132
|
+
while (entry != NULL)
|
|
133
|
+
{
|
|
134
|
+
if ( strcmp(entry->key, key) == 0 )
|
|
135
|
+
{
|
|
136
|
+
return entry->data;
|
|
137
|
+
}
|
|
138
|
+
entry = entry->next;
|
|
139
|
+
}
|
|
140
|
+
return NOTFOUND;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Find a particular key in the hash table
|
|
144
|
+
char *hashtable_findkey(HashTable *ht, char *key)
|
|
145
|
+
{
|
|
146
|
+
unsigned int i = gethash(key);
|
|
147
|
+
DataEntry *entry;
|
|
148
|
+
if ( i >= HASHTABLEMAXSIZE ) return NULL;
|
|
149
|
+
entry = ht[i];
|
|
150
|
+
while (entry != NULL)
|
|
151
|
+
{
|
|
152
|
+
if ( strcmp(entry->key, key) == 0 ) return entry->key;
|
|
153
|
+
entry = entry->next;
|
|
154
|
+
}
|
|
155
|
+
return NULL;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Delete a hash table and free all of its memory
|
|
159
|
+
void hashtable_free(HashTable *ht)
|
|
160
|
+
{
|
|
161
|
+
DataEntry *entry, *nextentry;
|
|
162
|
+
int i;
|
|
163
|
+
|
|
164
|
+
for (i = 0; i < HASHTABLEMAXSIZE; i++)
|
|
165
|
+
{
|
|
166
|
+
entry = ht[i];
|
|
167
|
+
while (entry != NULL)
|
|
168
|
+
{
|
|
169
|
+
nextentry = entry->next;
|
|
170
|
+
free(entry->key);
|
|
171
|
+
free(entry);
|
|
172
|
+
entry = nextentry;
|
|
173
|
+
}
|
|
174
|
+
ht[i] = NULL;
|
|
175
|
+
}
|
|
176
|
+
free(ht);
|
|
177
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/*
|
|
2
|
-
******************************************************************************
|
|
3
|
-
Project: OWA EPANET
|
|
4
|
-
Version: 2.
|
|
5
|
-
Module: hash.h
|
|
6
|
-
Description: header for a simple hash table
|
|
7
|
-
Authors: see AUTHORS
|
|
8
|
-
Copyright: see AUTHORS
|
|
9
|
-
License: see LICENSE
|
|
10
|
-
Last Updated: 11/27/2018
|
|
11
|
-
******************************************************************************
|
|
12
|
-
*/
|
|
13
|
-
#ifndef HASH_H
|
|
14
|
-
#define HASH_H
|
|
15
|
-
|
|
16
|
-
#define NOTFOUND 0
|
|
17
|
-
|
|
18
|
-
typedef struct DataEntryStruct *HashTable;
|
|
19
|
-
|
|
20
|
-
HashTable *hashtable_create(void);
|
|
21
|
-
int hashtable_insert(HashTable *,
|
|
22
|
-
int hashtable_find(HashTable *,
|
|
23
|
-
char *hashtable_findkey(HashTable *,
|
|
24
|
-
void hashtable_free(HashTable *);
|
|
25
|
-
int hashtable_update(HashTable *ht,
|
|
26
|
-
int hashtable_delete(HashTable *ht,
|
|
27
|
-
|
|
28
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.2
|
|
5
|
+
Module: hash.h
|
|
6
|
+
Description: header for a simple hash table
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 11/27/2018
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
#ifndef HASH_H
|
|
14
|
+
#define HASH_H
|
|
15
|
+
|
|
16
|
+
#define NOTFOUND 0
|
|
17
|
+
|
|
18
|
+
typedef struct DataEntryStruct *HashTable;
|
|
19
|
+
|
|
20
|
+
HashTable *hashtable_create(void);
|
|
21
|
+
int hashtable_insert(HashTable *, char *, int);
|
|
22
|
+
int hashtable_find(HashTable *, char *);
|
|
23
|
+
char *hashtable_findkey(HashTable *, char *);
|
|
24
|
+
void hashtable_free(HashTable *);
|
|
25
|
+
int hashtable_update(HashTable *ht, char *key, int new_data);
|
|
26
|
+
int hashtable_delete(HashTable *ht, char *key);
|
|
27
|
+
|
|
28
|
+
#endif
|