From c1e9dd47db9f61b5d6863d2d7ef83cc5e2e0c855 Mon Sep 17 00:00:00 2001 From: cdez Date: Mon, 13 Nov 2023 15:09:13 -0700 Subject: [PATCH] Finished StateDataUtility, Started HashUtility +- HashUtiltity.c +- StateDataUtility.c --- PA10-1115/HashUtility.c | 25 +++++++++++++++++++++++-- PA10-1115/StateDataUtility.c | 8 +++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/PA10-1115/HashUtility.c b/PA10-1115/HashUtility.c index 9718b22..1015d8b 100644 --- a/PA10-1115/HashUtility.c +++ b/PA10-1115/HashUtility.c @@ -71,6 +71,10 @@ Dependencies: free */ void clearHashTable( ProbingHashType *hashTable ) { + // free the internal array + free(hashTable->array); + // free the rest of the structure + free(hashTable); // no return, void. } @@ -166,8 +170,25 @@ Dependencies: malloc, setEmptyDataNode, */ ProbingHashType *initializeHashTable( int capacity, ProbeType probe ) { - // return NULL (temp) - return NULL; + int initIterator; + // use malloc to initialize the table + ProbingHashType *createdHashTable = + (ProbingHashType *) malloc(sizeof(ProbingHashType)); + // use malloc to create the array + createdHashTable->array = + (StateDataType *) malloc(sizeof(StateDataType) * capacity); + // iterate through the entire array, set to empty data + for(initIterator = 0; initIterator < capacity; initIterator++) + { + // set the array's items to empty. + setEmptyDataNode(&createdHashTable->array[initIterator]); + } + // define the size of the table to capacity. + createdHashTable->tableSize = capacity; + // define the probing strategy given. + createdHashTable->probeStrategy = probe; + // return the created hash table + return createdHashTable; } /* diff --git a/PA10-1115/StateDataUtility.c b/PA10-1115/StateDataUtility.c index eb8512d..8e731b7 100644 --- a/PA10-1115/StateDataUtility.c +++ b/PA10-1115/StateDataUtility.c @@ -75,7 +75,7 @@ Dependencies: sprintf, or other options void stateDataToString( char *outStr, const StateDataType state ) { // get the data out using sprintf - sprintf(outStr, "%s, Avg: %0.2f, Low: %0.2f, High: %0.2f,", state.name, + sprintf(outStr, "%s, Avg: %0.2f, Low: %0.2f, High: %0.2f", state.name, state.averageTemp, state.lowestTemp, state.highestTemp); // no return, void. } @@ -93,5 +93,11 @@ Dependencies: privateCopyString */ void setEmptyDataNode( StateDataType *node ) { + // fill the node with blank data. + privateCopyString(node->name, "---"); + node->averageTemp = 0; + node->highestTemp = 0; + node->lowestTemp = 0; + node->inUse = false; // no return, void. } \ No newline at end of file