#include <stdlib.h>
#include <string.h>
#include "hash.h"
#include "util.h"
Go to the source code of this file.
struct s_hash** alloc_hash_table |
( |
void |
| ) |
|
Definition at line 7 of file hash.c.
11 struct s_hash **hash_table;
void * my_calloc(size_t nelem, size_t size)
void free_hash_table |
( |
struct s_hash ** |
hash_table | ) |
|
Definition at line 18 of file hash.c.
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;
struct s_hash* get_hash_entry |
( |
struct s_hash ** |
hash_table, |
|
|
char * |
name |
|
) |
| |
Definition at line 119 of file hash.c.
128 h_ptr = hash_table[i];
130 while (h_ptr != NULL) {
int hash_value(char *name)
void get_hash_stats |
( |
struct s_hash ** |
hash_table, |
|
|
char * |
hash_table_name |
|
) |
| |
Definition at line 160 of file hash.c.
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);
Definition at line 51 of file hash.c.
60 h_ptr = hash_iterator->
h_ptr;
62 while (h_ptr == NULL) {
67 h_ptr = hash_table[i];
int hash_value |
( |
char * |
name | ) |
|
Definition at line 140 of file hash.c.
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];
struct s_hash* insert_in_hash_table |
( |
struct s_hash ** |
hash_table, |
|
|
char * |
name, |
|
|
int |
next_free_index |
|
) |
| |
Definition at line 76 of file hash.c.
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;
int hash_value(char *name)
static void * my_malloc(int ibytes)
Definition at line 38 of file hash.c.
46 hash_iterator.h_ptr = NULL;
47 return (hash_iterator);