diff --git a/HashTable/HashTable.c b/HashTable/HashTable.c index 59ac84f..a3c1ab8 100644 --- a/HashTable/HashTable.c +++ b/HashTable/HashTable.c @@ -35,7 +35,7 @@ typedef struct HashTable LinkedList* allocate_list(void) { - LinkedList* list = (LinkedList*)malloc(sizeof(LinkedList)); + LinkedList* list = (LinkedList*) malloc(sizeof(LinkedList)); return list; } @@ -99,7 +99,7 @@ void free_linkedlist(LinkedList* list) LinkedList** create_overflow_buckets(HashTable* table) { - LinkedList** buckets = (LinkedList**)calloc(table->size, sizeof(LinkedList*)); + LinkedList** buckets = (LinkedList**) calloc(table->size, sizeof(LinkedList*)); for (int i = 0; i < table->size; i++) buckets[i] = NULL; return buckets; } @@ -113,9 +113,9 @@ void free_overflow_buckets(HashTable* table) Ht_item* create_item(char* key, char* value) { - Ht_item* item = (Ht_item*)malloc(sizeof(Ht_item)); - item->key = (char*)malloc(strlen(key) + 1); - item->value = (char*)malloc(strlen(value) + 1); + Ht_item* item = (Ht_item*) malloc(sizeof(Ht_item)); + item->key = (char*) malloc(strlen(key) + 1); + item->value = (char*) malloc(strlen(value) + 1); strcpy(item->key, key); strcpy(item->value, value); return item; @@ -123,7 +123,7 @@ Ht_item* create_item(char* key, char* value) HashTable* create_table(int size) { - HashTable* table = (HashTable*)malloc(sizeof(HashTable)); + HashTable* table = (HashTable*) malloc(sizeof(HashTable)); table->size = size; table->count = 0; table->items = (Ht_item**)calloc(table->size, sizeof(Ht_item*)); @@ -171,7 +171,7 @@ void handle_collision(HashTable* table, unsigned long index, Ht_item* item) void ht_insert(HashTable* table, char* key, char* value) { Ht_item* item = create_item(key, value); - int index = (int)hash_function(key); + int index = (int) hash_function(key); Ht_item* current_item = table->items[index]; if (current_item == NULL) { @@ -201,7 +201,7 @@ void ht_insert(HashTable* table, char* key, char* value) char* ht_search(HashTable* table, char* key) { - int index = (int)hash_function(key); + int index = (int) hash_function(key); Ht_item* item = table->items[index]; LinkedList* head = table->overflow_buckets[index]; if (item != NULL) @@ -216,7 +216,7 @@ char* ht_search(HashTable* table, char* key) void ht_delete(HashTable* table, char* key) { - int index = (int)hash_function(key); + int index = (int) hash_function(key); Ht_item* item = table->items[index]; LinkedList* head = table->overflow_buckets[index]; if (item == NULL) @@ -303,18 +303,18 @@ void print_table(HashTable* table) int main(void) { HashTable* ht = create_table(CAPACITY); - ht_insert(ht, (char*)"1", (char*)"First address"); - ht_insert(ht, (char*)"2", (char*)"Second address"); - ht_insert(ht, (char*)"Hel", (char*)"Third address"); - ht_insert(ht, (char*)"Cau", (char*)"Fourth address"); - print_search(ht, (char*)"1"); - print_search(ht, (char*)"2"); - print_search(ht, (char*)"3"); - print_search(ht, (char*)"Hel"); - print_search(ht, (char*)"Cau"); + ht_insert(ht, (char*) "1", (char*) "First address"); + ht_insert(ht, (char*) "2", (char*) "Second address"); + ht_insert(ht, (char*) "Hel", (char*) "Third address"); + ht_insert(ht, (char*) "Cau", (char*) "Fourth address"); + print_search(ht, (char*) "1"); + print_search(ht, (char*) "2"); + print_search(ht, (char*) "3"); + print_search(ht, (char*) "Hel"); + print_search(ht, (char*) "Cau"); print_table(ht); - ht_delete(ht, (char*)"1"); - ht_delete(ht, (char*)"Cau"); + ht_delete(ht, (char*) "1"); + ht_delete(ht, (char*) "Cau"); print_table(ht); free_table(ht); return 0; diff --git a/HashTable/x64/Debug/HashTable.exe b/HashTable/x64/Debug/HashTable.exe new file mode 100644 index 0000000..e81ba32 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.exe differ diff --git a/HashTable/x64/Debug/HashTable.exe.recipe b/HashTable/x64/Debug/HashTable.exe.recipe new file mode 100644 index 0000000..3a0147a --- /dev/null +++ b/HashTable/x64/Debug/HashTable.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\LukeH\Desktop\C-Examples\HashTable\x64\Debug\HashTable.exe + + + + + + \ No newline at end of file diff --git a/HashTable/x64/Debug/HashTable.ilk b/HashTable/x64/Debug/HashTable.ilk new file mode 100644 index 0000000..be05e2a Binary files /dev/null and b/HashTable/x64/Debug/HashTable.ilk differ diff --git a/HashTable/x64/Debug/HashTable.log b/HashTable/x64/Debug/HashTable.log new file mode 100644 index 0000000..54054c1 --- /dev/null +++ b/HashTable/x64/Debug/HashTable.log @@ -0,0 +1,2 @@ + HashTable.c + HashTable.vcxproj -> C:\Users\LukeH\Desktop\C-Examples\HashTable\x64\Debug\HashTable.exe diff --git a/HashTable/x64/Debug/HashTable.obj b/HashTable/x64/Debug/HashTable.obj new file mode 100644 index 0000000..1307682 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.obj differ diff --git a/HashTable/x64/Debug/HashTable.pdb b/HashTable/x64/Debug/HashTable.pdb new file mode 100644 index 0000000..9bc829d Binary files /dev/null and b/HashTable/x64/Debug/HashTable.pdb differ diff --git a/HashTable/x64/Debug/HashTable.tlog/CL.command.1.tlog b/HashTable/x64/Debug/HashTable.tlog/CL.command.1.tlog new file mode 100644 index 0000000..efc0c34 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/CL.command.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.tlog/CL.read.1.tlog b/HashTable/x64/Debug/HashTable.tlog/CL.read.1.tlog new file mode 100644 index 0000000..67e7067 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/CL.read.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.tlog/CL.write.1.tlog b/HashTable/x64/Debug/HashTable.tlog/CL.write.1.tlog new file mode 100644 index 0000000..ca05387 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/CL.write.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.tlog/Cl.items.tlog b/HashTable/x64/Debug/HashTable.tlog/Cl.items.tlog new file mode 100644 index 0000000..4969734 --- /dev/null +++ b/HashTable/x64/Debug/HashTable.tlog/Cl.items.tlog @@ -0,0 +1 @@ +C:\Users\LukeH\Desktop\C-Examples\HashTable\HashTable.c;C:\Users\LukeH\Desktop\C-Examples\HashTable\x64\Debug\HashTable.obj diff --git a/HashTable/x64/Debug/HashTable.tlog/HashTable.lastbuildstate b/HashTable/x64/Debug/HashTable.tlog/HashTable.lastbuildstate new file mode 100644 index 0000000..87b8a8b --- /dev/null +++ b/HashTable/x64/Debug/HashTable.tlog/HashTable.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.36.32532:TargetPlatformVersion=10.0.22000.0: +Debug|x64|C:\Users\LukeH\Desktop\C-Examples\HashTable\| diff --git a/HashTable/x64/Debug/HashTable.tlog/link.command.1.tlog b/HashTable/x64/Debug/HashTable.tlog/link.command.1.tlog new file mode 100644 index 0000000..ace51df Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/link.command.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.tlog/link.read.1.tlog b/HashTable/x64/Debug/HashTable.tlog/link.read.1.tlog new file mode 100644 index 0000000..edae7e2 Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/link.read.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.tlog/link.write.1.tlog b/HashTable/x64/Debug/HashTable.tlog/link.write.1.tlog new file mode 100644 index 0000000..e25d70c Binary files /dev/null and b/HashTable/x64/Debug/HashTable.tlog/link.write.1.tlog differ diff --git a/HashTable/x64/Debug/HashTable.vcxproj.FileListAbsolute.txt b/HashTable/x64/Debug/HashTable.vcxproj.FileListAbsolute.txt new file mode 100644 index 0000000..dd7cda3 --- /dev/null +++ b/HashTable/x64/Debug/HashTable.vcxproj.FileListAbsolute.txt @@ -0,0 +1 @@ +C:\Users\LukeH\Desktop\C-Examples\HashTable\x64\Debug\HashTable.exe diff --git a/HashTable/x64/Debug/vc143.idb b/HashTable/x64/Debug/vc143.idb new file mode 100644 index 0000000..2a16232 Binary files /dev/null and b/HashTable/x64/Debug/vc143.idb differ diff --git a/HashTable/x64/Debug/vc143.pdb b/HashTable/x64/Debug/vc143.pdb new file mode 100644 index 0000000..9fe486b Binary files /dev/null and b/HashTable/x64/Debug/vc143.pdb differ diff --git a/main.c b/main.c index ebfede5..141aa32 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ typedef struct HashTable LinkedList *allocate_list(void) { - LinkedList *list = (LinkedList *)malloc(sizeof(LinkedList)); + LinkedList *list = (LinkedList *) malloc(sizeof(LinkedList)); return list; } @@ -97,7 +97,7 @@ void free_linkedlist(LinkedList *list) LinkedList **create_overflow_buckets(HashTable *table) { - LinkedList **buckets = (LinkedList **)calloc(table->size, sizeof(LinkedList *)); + LinkedList **buckets = (LinkedList **) calloc(table->size, sizeof(LinkedList *)); for (int i = 0; i < table->size; i++) buckets[i] = NULL; return buckets; } @@ -111,9 +111,9 @@ void free_overflow_buckets(HashTable *table) Ht_item *create_item(char *key, char *value) { - Ht_item *item = (Ht_item *)malloc(sizeof(Ht_item)); - item->key = (char *)malloc(strlen(key) + 1); - item->value = (char *)malloc(strlen(value) + 1); + Ht_item *item = (Ht_item *) malloc(sizeof(Ht_item)); + item->key = (char *) malloc(strlen(key) + 1); + item->value = (char *) malloc(strlen(value) + 1); strcpy(item->key, key); strcpy(item->value, value); return item; @@ -121,10 +121,10 @@ Ht_item *create_item(char *key, char *value) HashTable *create_table(int size) { - HashTable *table = (HashTable *)malloc(sizeof(HashTable)); + HashTable *table = (HashTable *) malloc(sizeof(HashTable)); table->size = size; table->count = 0; - table->items = (Ht_item **)calloc(table->size, sizeof(Ht_item *)); + table->items = (Ht_item **) calloc(table->size, sizeof(Ht_item *)); for (int i = 0; i < table->size; i++) table->items[i] = NULL; table->overflow_buckets = create_overflow_buckets(table); return table; @@ -292,7 +292,7 @@ void print_table(HashTable *table) { if (table -> items[i]) { - printf("Index:%d, Key:%s, Value:%s\n", i, table -> items[i] -> key, table -> items[i] -> value); + printf("Index:%d, Key:%s, Value:%s\n", i, table->items[i]->key, table->items[i]->value); } } printf("-------------------\n\n");