Finished StateDataUtility, Started HashUtility
+- HashUtiltity.c +- StateDataUtility.c
This commit is contained in:
parent
6969f405e3
commit
c1e9dd47db
2 changed files with 30 additions and 3 deletions
|
|
@ -71,6 +71,10 @@ Dependencies: free
|
||||||
*/
|
*/
|
||||||
void clearHashTable( ProbingHashType *hashTable )
|
void clearHashTable( ProbingHashType *hashTable )
|
||||||
{
|
{
|
||||||
|
// free the internal array
|
||||||
|
free(hashTable->array);
|
||||||
|
// free the rest of the structure
|
||||||
|
free(hashTable);
|
||||||
// no return, void.
|
// no return, void.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,8 +170,25 @@ Dependencies: malloc, setEmptyDataNode,
|
||||||
*/
|
*/
|
||||||
ProbingHashType *initializeHashTable( int capacity, ProbeType probe )
|
ProbingHashType *initializeHashTable( int capacity, ProbeType probe )
|
||||||
{
|
{
|
||||||
// return NULL (temp)
|
int initIterator;
|
||||||
return NULL;
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ Dependencies: sprintf, or other options
|
||||||
void stateDataToString( char *outStr, const StateDataType state )
|
void stateDataToString( char *outStr, const StateDataType state )
|
||||||
{
|
{
|
||||||
// get the data out using sprintf
|
// 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);
|
state.averageTemp, state.lowestTemp, state.highestTemp);
|
||||||
// no return, void.
|
// no return, void.
|
||||||
}
|
}
|
||||||
|
|
@ -93,5 +93,11 @@ Dependencies: privateCopyString
|
||||||
*/
|
*/
|
||||||
void setEmptyDataNode( StateDataType *node )
|
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 return, void.
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue