diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 189276a9..7551fe2f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -904,16 +904,11 @@ void Phreeqc::init(void) remove_unstable_phases = FALSE; // auto screen_string; spread_length = 10; - /* ---------------------------------------------------------------------- */ - /* - * Hash definitions - */ - master_isotope_hash_table = NULL; /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ initial_solution_isotopes = FALSE; - calculate_value_hash_table = NULL; + calculate_value_hash_table = NULL; isotope_ratio_hash_table = 0; isotope_alpha_hash_table = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 930b7245..4614233a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1665,7 +1665,7 @@ protected: std::map species_map; std::map phases_map; std::map logk_map; - HashTable *master_isotope_hash_table; + std::map master_isotope_map; #if defined(PHREEQCI_GUI) #include "../../phreeqci_gui.h" diff --git a/isotopes.cpp b/isotopes.cpp index 21b8515c..fce9d49d 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -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::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::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); diff --git a/mainsubs.cpp b/mainsubs.cpp index fcebbacc..75ac03fb 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -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)); diff --git a/structures.cpp b/structures.cpp index 38303481..aaaefd80 100644 --- a/structures.cpp +++ b/structures.cpp @@ -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++) {