mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 00:28:23 +01:00
replace logk_hash_table with logk_map. Added str_tolower(std::string)
This commit is contained in:
parent
3e69461cf8
commit
c01c8d66bf
@ -908,7 +908,6 @@ void Phreeqc::init(void)
|
||||
/*
|
||||
* Hash definitions
|
||||
*/
|
||||
logk_hash_table = NULL;
|
||||
master_isotope_hash_table = NULL;
|
||||
/* ----------------------------------------------------------------------
|
||||
* ISOTOPES
|
||||
|
||||
@ -1117,6 +1117,7 @@ public:
|
||||
static bool replace(const char *str1, const char *str2, std::string & str);
|
||||
static int strcmp_nocase(const char *str1, const char *str2);
|
||||
static int strcmp_nocase_arg1(const char *str1, const char *str2);
|
||||
static void str_tolower(std::string &name);
|
||||
protected:
|
||||
void space(void **ptr, int i, int *max, int struct_size);
|
||||
void squeeze_white(char *s_l);
|
||||
@ -1656,15 +1657,14 @@ protected:
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Hash definitions
|
||||
* Map definitions
|
||||
*/
|
||||
|
||||
std::map<std::string, std::string *> strings_map;
|
||||
std::map<std::string, struct element*> elements_map;
|
||||
std::map<std::string, struct species*> species_map;
|
||||
std::map<std::string, struct phase*> phases_map;
|
||||
|
||||
HashTable *logk_hash_table;
|
||||
std::map<std::string, struct logk*> logk_map;
|
||||
HashTable *master_isotope_hash_table;
|
||||
|
||||
#if defined(PHREEQCI_GUI)
|
||||
|
||||
@ -64,7 +64,6 @@ initialize(void)
|
||||
/*
|
||||
* Create hash tables
|
||||
*/
|
||||
hcreate_multi((unsigned) MAX_S, &logk_hash_table);
|
||||
hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table);
|
||||
|
||||
// user_print
|
||||
|
||||
@ -235,9 +235,8 @@ clean_up(void)
|
||||
/* hash tables */
|
||||
elements_map.clear();
|
||||
species_map.clear();
|
||||
hdestroy_multi(logk_hash_table);
|
||||
phases_map.clear();
|
||||
logk_hash_table = NULL;
|
||||
logk_map.clear();
|
||||
/* strings */
|
||||
strings_map_clear();
|
||||
/* delete basic interpreter */
|
||||
@ -1944,7 +1943,7 @@ s_search(const char* name)
|
||||
struct species* s_ptr = NULL;
|
||||
std::map<std::string, struct species*>::iterator s_it =
|
||||
species_map.find(name);
|
||||
if (s_it == species_map.find(name))
|
||||
if (s_it != species_map.end())
|
||||
{
|
||||
s_ptr = s_it->second;
|
||||
}
|
||||
@ -3037,11 +3036,11 @@ logk_store(char *name, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for logk.
|
||||
* Function locates the string "name" in the map for logk.
|
||||
*
|
||||
* Pointer to a logk structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old logk structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -3056,24 +3055,22 @@ logk_store(char *name, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to logk structure "logk" where "name" can be found.
|
||||
*/
|
||||
struct logk *logk_ptr;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
struct logk* logk_ptr;
|
||||
str_tolower(name);
|
||||
item.key = name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
std::map<std::string, struct logk*>::iterator l_it =
|
||||
logk_map.find(name);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
if (l_it != logk_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = l_it->second;
|
||||
return (logk_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (l_it != logk_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = l_it->second;
|
||||
logk_init(logk_ptr);
|
||||
}
|
||||
else
|
||||
@ -3087,17 +3084,9 @@ logk_store(char *name, int replace_if_found)
|
||||
/* set name and z in pointer in logk structure */
|
||||
logk_ptr->name = string_hsave(name);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = logk_ptr->name;
|
||||
item.data = (void *) logk_ptr;
|
||||
found_item = hsearch_multi(logk_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in logk_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
logk_map[name] = logk_ptr;
|
||||
return (logk_ptr);
|
||||
}
|
||||
|
||||
@ -3182,19 +3171,16 @@ logk_search(const char *name_in)
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct logk *logk_ptr;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
char * name = string_duplicate(name_in);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
item.key = name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
free_check_null(name);
|
||||
if (found_item != NULL)
|
||||
std::map<std::string, struct logk*>::iterator l_it =
|
||||
logk_map.find(name);
|
||||
if (l_it != logk_map.end())
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = l_it->second;
|
||||
return (logk_ptr);
|
||||
}
|
||||
return (NULL);
|
||||
|
||||
21
tidy.cpp
21
tidy.cpp
@ -558,7 +558,6 @@ add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
struct logk *logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
LDBLE coef;
|
||||
ENTRY item, *found_item;
|
||||
|
||||
if (count_add_logk == 0)
|
||||
return (OK);
|
||||
@ -567,10 +566,8 @@ add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
coef = add_logk[i].coef;
|
||||
strcpy(token, add_logk[i].name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
if (found_item == NULL)
|
||||
std::map<std::string, struct logk *>::iterator l_it = logk_map.find(token);
|
||||
if (l_it == logk_map.end())
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -579,7 +576,7 @@ add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
logk_ptr = (struct logk *) found_item->data;
|
||||
logk_ptr = l_it->second;
|
||||
analytic = FALSE;
|
||||
for (j = T_A1; j <= T_A6; j++)
|
||||
{
|
||||
@ -616,9 +613,7 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
{
|
||||
int i, j;
|
||||
struct logk *next_logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
LDBLE coef;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Adds in other named_expressions to get complete log K
|
||||
* Evaluates others recursively if necessary
|
||||
@ -634,12 +629,10 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
for (i = 0; i < logk_ptr->count_add_logk; i++)
|
||||
{
|
||||
coef = logk_ptr->add_logk[i].coef;
|
||||
strcpy(token, logk_ptr->add_logk[i].name);
|
||||
std::string token = logk_ptr->add_logk[i].name;
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
if (found_item == NULL)
|
||||
std::map<std::string, struct logk*>::iterator l_it = logk_map.find(token);
|
||||
if (l_it == logk_map.end())
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -648,7 +641,7 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
next_logk_ptr = (struct logk *) found_item->data;
|
||||
next_logk_ptr = l_it->second;
|
||||
if (next_logk_ptr->done == FALSE)
|
||||
{
|
||||
/*output_msg(sformatf( "Done == FALSE\n", token)); */
|
||||
|
||||
@ -1187,7 +1187,10 @@ strcmp_nocase(const char *str1, const char *str2)
|
||||
return (-1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void Phreeqc::str_tolower(std::string &name)
|
||||
{
|
||||
std::transform(name.begin(), name.end(), name.begin(), std::tolower);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
strcmp_nocase_arg1(const char *str1, const char *str2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user