#include "cmp.h" #include #include /*cmp_string takes two void* and compares their values as strings. * Actually, it should probably work an any data type, it just uses strcmp * returns 0 if they are the same, something else if they are different */ int cmp_string(const void *a, const void *b) { assert(a != NULL); assert(b != NULL); char* a_ch = (char*)a; char* b_ch = (char*)b; return strcmp(a_ch, b_ch); } int cmp_double(const void *a, const void *b) { assert(a != NULL); assert(b != NULL); return (*((double*)a) != *((double*)b)); } /*hashes the string for the hash table. Only gets you a number between 0 and 50, so the hash * isn't exactly very good. But, it is a hash * */ int hash_string(const void *element) { char *to_hash = (char*) element; int hash = 0; int pos = 0; while(to_hash[pos] != '\0') { hash += to_hash[pos++]; } return hash; }