From 60c4499f101f8a5acdf62e6f4cf307b15821d8fd Mon Sep 17 00:00:00 2001 From: Tanner Babcock Date: Fri, 12 Jul 2024 16:30:08 -0500 Subject: [PATCH] Hopefully fix hashtable CI --- point/hashtable.c | 68 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/point/hashtable.c b/point/hashtable.c index 2b85a60..117dcca 100644 --- a/point/hashtable.c +++ b/point/hashtable.c @@ -17,7 +17,7 @@ typedef struct hashTable_t { * linked list */ } hashTable; -hashTable *ht_create(unsigned int size) { +static hashTable *ht_create(unsigned int size) { hashTable *ht; if (size < 1) return NULL; @@ -39,7 +39,7 @@ hashTable *ht_create(unsigned int size) { } /* free the items in a hashTable. free each individual row and column */ -void ht_free(hashTable *ht) { +static void ht_free(hashTable *ht) { list *tmp; if (!ht) @@ -62,7 +62,7 @@ void ht_free(hashTable *ht) { free(ht); } -unsigned int hash(const char *key, unsigned int size) { +static unsigned int hash(const char *key, unsigned int size) { unsigned int hash = 0, i = 0; while (key && key[i]) { @@ -72,7 +72,36 @@ unsigned int hash(const char *key, unsigned int size) { return hash; } -int ht_put(hashTable *ht, const char *key, const char *value) { +static void node_handle(hashTable *ht, list *node) { + unsigned int i = hash(node->key, ht->size); + list *tmp = ht->array[i]; + + if (ht->array[i] != NULL) { + tmp = ht->array[i]; + while (tmp != NULL) { + if (strcmp(tmp->key, node->key) == 0) + break; + tmp = tmp->next; + } + if (tmp == NULL) { + node->next = ht->array[i]; + ht->array[i] = node; + } + else { + free(tmp->value); + tmp->value = strdup(node->value); + free(node->value); + free(node->key); + free(node); + } + } + else { + node->next = NULL; + ht->array[i] = node; + } +} + +static int ht_put(hashTable *ht, const char *key, const char *value) { list *node; if (!ht) { @@ -92,7 +121,7 @@ int ht_put(hashTable *ht, const char *key, const char *value) { return 0; } -char *ht_get(hashTable *ht, const char *key) { +static char *ht_get(hashTable *ht, const char *key) { char *key_cp; unsigned int i; list *tmp; @@ -118,35 +147,6 @@ char *ht_get(hashTable *ht, const char *key) { return tmp->value; } -void node_handle(hashTable *ht, list *node) { - unsigned int i = hash(node->key, ht->size); - list *tmp = ht->array[i]; - - if (ht->array[i] != NULL) { - tmp = ht->array[i]; - while (tmp != NULL) { - if (strcmp(tmp->key, node->key) == 0) - break; - tmp = tmp->next; - } - if (tmp == NULL) { - node->next = ht->array[i]; - ht->array[i] = node; - } - else { - free(tmp->value); - tmp->value = strdup(node->value); - free(node->value); - free(node->key); - free(node); - } - } - else { - node->next = NULL; - ht->array[i] = node; - } -} - int main(void) { hashTable *ht; if (!(ht = ht_create(1))) {