replase master_isotope_hash_table with master_isotope_map

This commit is contained in:
David Parkhurst 2021-03-21 21:42:49 -06:00
parent c01c8d66bf
commit 52e0622596
5 changed files with 20 additions and 54 deletions

View File

@ -904,11 +904,6 @@ void Phreeqc::init(void)
remove_unstable_phases = FALSE;
// auto screen_string;
spread_length = 10;
/* ---------------------------------------------------------------------- */
/*
* Hash definitions
*/
master_isotope_hash_table = NULL;
/* ----------------------------------------------------------------------
* ISOTOPES
* ---------------------------------------------------------------------- */

View File

@ -1665,7 +1665,7 @@ protected:
std::map<std::string, struct species*> species_map;
std::map<std::string, struct phase*> phases_map;
std::map<std::string, struct logk*> logk_map;
HashTable *master_isotope_hash_table;
std::map<std::string, struct master_isotope*> master_isotope_map;
#if defined(PHREEQCI_GUI)
#include "../../phreeqci_gui.h"

View File

@ -1325,25 +1325,19 @@ master_isotope_store(const char *name, int replace_if_found)
*/
int n;
struct master_isotope *master_isotope_ptr;
ENTRY item, *found_item;
char token[MAX_LENGTH];
/*
* Search list
*/
strcpy(token, name);
item.key = token;
item.data = NULL;
found_item = hsearch_multi(master_isotope_hash_table, item, FIND);
if (found_item != NULL && replace_if_found == FALSE)
std::map<std::string, struct master_isotope*>::iterator mi_it =
master_isotope_map.find(name);
if (mi_it != master_isotope_map.end() && replace_if_found == FALSE)
{
master_isotope_ptr = (struct master_isotope *) (found_item->data);
master_isotope_ptr = mi_it->second;
return (master_isotope_ptr);
}
else if (found_item != NULL && replace_if_found == TRUE)
else if (mi_it != master_isotope_map.end() && replace_if_found == TRUE)
{
master_isotope_ptr = (struct master_isotope *) (found_item->data);
master_isotope_ptr = mi_it->second;
master_isotope_init(master_isotope_ptr);
}
else
@ -1355,19 +1349,11 @@ master_isotope_store(const char *name, int replace_if_found)
master_isotope_ptr = master_isotope[n];
}
/* set name and z in pointer in master_isotope structure */
master_isotope_ptr->name = string_hsave(token);
master_isotope_ptr->name = string_hsave(name);
/*
* Update hash table
* Update map
*/
item.key = master_isotope_ptr->name;
item.data = (void *) master_isotope_ptr;
found_item = hsearch_multi(master_isotope_hash_table, item, ENTER);
if (found_item == NULL)
{
error_string = sformatf( "Hash table error in master_isotope_store.");
error_msg(error_string, CONTINUE);
}
master_isotope_map[name] = master_isotope_ptr;
return (master_isotope_ptr);
}
@ -1381,11 +1367,7 @@ master_isotope_alloc(void)
* return: pointer to a master_isotope structure
*/
{
struct master_isotope *master_isotope_ptr;
master_isotope_ptr =
(struct master_isotope *) PHRQ_malloc(sizeof(struct master_isotope));
if (master_isotope_ptr == NULL)
malloc_error();
struct master_isotope *master_isotope_ptr = new struct master_isotope;
/*
* set pointers in structure to NULL, variables to zero
*/
@ -1427,7 +1409,7 @@ master_isotope_search(const char *name)
/* ---------------------------------------------------------------------- */
{
/*
* Function locates the string "name" in the hash table for master_isotope.
* Function locates the string "name" in the map for master_isotope.
*
* Arguments:
* name input, character string to be found in "master_isotope".
@ -1436,21 +1418,15 @@ master_isotope_search(const char *name)
* pointer to master_isotope structure "master_isotope" where "name" can be found.
* or NULL if not found.
*/
struct master_isotope *master_isotope_ptr;
ENTRY item, *found_item;
char token[MAX_LENGTH];
struct master_isotope* master_isotope_ptr = NULL;
/*
* Search list
*/
strcpy(token, name);
item.key = token;
item.data = NULL;
found_item = hsearch_multi(master_isotope_hash_table, item, FIND);
if (found_item != NULL)
std::map<std::string, struct master_isotope*>::iterator mi_it =
master_isotope_map.find(name);
if (mi_it != master_isotope_map.end())
{
master_isotope_ptr = (struct master_isotope *) (found_item->data);
master_isotope_ptr = mi_it->second;
return (master_isotope_ptr);
}
return (NULL);

View File

@ -61,10 +61,6 @@ initialize(void)
stag_data->exch_f = 0;
stag_data->th_m = 0;
stag_data->th_im = 0;
/*
* Create hash tables
*/
hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table);
// user_print
user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));

View File

@ -192,11 +192,10 @@ clean_up(void)
/* master_isotope */
for (i = 0; i < (int)master_isotope.size(); i++)
{
master_isotope[i] = (struct master_isotope*)free_check_null(master_isotope[i]);
delete master_isotope[i];
}
master_isotope.clear();
hdestroy_multi(master_isotope_hash_table);
master_isotope_hash_table = NULL;
master_isotope_map.clear();
/* calculate_value */
for (i = 0; i < (int)calculate_value.size(); i++)
{