#include #include #include #include #include #include "hash-table.h" #include "constant.h" long long hash_function(char *key) { long long hash = 0; for (int i=0; ikey, key); // init for (short i=0; ivalue[i] = 0.0; } node->next = NULL; if (table[hash] == NULL){ table[hash] = node; } else { temp = table[hash]; past = NULL; while(temp != NULL){ assert(strcmp(temp->key, key)!=0); past = temp; temp = temp->next; } past->next = node; } } void search(struct Node **table, char *key, bool *find, float *ans) { long long hash = hash_function(key); struct Node *temp, *past; *find = false; if (table[hash] != NULL){ temp = table[hash]; past = NULL; while(temp != NULL){ if (strcmp(temp->key, key) == 0){ *find = true; for (short i=0; ivalue[i]; } break; } past = temp; temp = temp->next; } } } void update(struct Node **table, char *key, short action, float value) { long long hash = hash_function(key); struct Node *temp, *past; assert(table[hash]!=NULL); temp = table[hash]; past = NULL; while(temp != NULL){ if (strcmp(temp->key, key) == 0){ temp->value[action] = value; break; } past = temp; temp = temp->next; } }