11 struct s_hash **hash_table;
23 struct s_hash *h_ptr, *temp_ptr;
26 h_ptr = hash_table[i];
27 while (h_ptr != NULL) {
29 temp_ptr = h_ptr->
next;
46 hash_iterator.
h_ptr = NULL;
47 return (hash_iterator);
60 h_ptr = hash_iterator->
h_ptr;
62 while (h_ptr == NULL) {
67 h_ptr = hash_table[i];
77 int next_free_index) {
86 struct s_hash *h_ptr, *prev_ptr;
90 h_ptr = hash_table[i];
92 while (h_ptr != NULL) {
93 if (strcmp(h_ptr->
name, name) == 0) {
105 if (prev_ptr == NULL) {
106 hash_table[i] = h_ptr;
108 prev_ptr->
next = h_ptr;
111 h_ptr->
index = next_free_index;
113 h_ptr->
name = (
char *)
my_malloc((strlen(name) + 1) *
sizeof(
char));
114 strcpy(h_ptr->
name, name);
128 h_ptr = hash_table[i];
130 while (h_ptr != NULL) {
131 if (strcmp(h_ptr->
name, name) == 0)
146 int val = 0, mult = 1;
149 for (i = strlen(name) - 1; i >= 0; i--) {
150 val += mult * ((int) name[i]);
153 val += (int) name[0];
168 int num_NULL = 0, total_elements = 0, max_num = 0, curr_num;
174 h_ptr = hash_table[i];
180 while (h_ptr != NULL){
186 if (curr_num > max_num)
189 total_elements = total_elements + curr_num;
192 avg_num = (float) total_elements / ((
float)HASHSIZE - (float)num_NULL);
195 vpr_printf(TIO_MESSAGE_INFO,
"The hash table '%s' is of size %d.\n",
196 hash_table_name, HASHSIZE);
197 vpr_printf(TIO_MESSAGE_INFO,
"It has: %d keys that are never used; total of %d elements; an average linked-list length of %.1f; and a maximum linked-list length of %d.\n",
198 num_NULL, total_elements, avg_num, max_num);
struct s_hash ** alloc_hash_table(void)
struct s_hash_iterator start_hash_table_iterator(void)
struct s_hash * get_hash_entry(struct s_hash **hash_table, char *name)
int hash_value(char *name)
void * my_calloc(size_t nelem, size_t size)
void free_hash_table(struct s_hash **hash_table)
static void * my_malloc(int ibytes)
struct s_hash * get_next_hash(struct s_hash **hash_table, struct s_hash_iterator *hash_iterator)
struct s_hash * insert_in_hash_table(struct s_hash **hash_table, char *name, int next_free_index)
void get_hash_stats(struct s_hash **hash_table, char *hash_table_name)