/* ============================================================================ Name : DogMap.c Author : David Mutchler and YOUR-NAME-HERE, November 2008. Description : The basics of a Map data structure that maps Dog names to pointers to Dog objects. ============================================================================ */ #ifndef DOGMAP_H_ #define DOGMAP_H_ #include "Dog.h" typedef struct { char* key; Dog* dog; } KeyDogPair; // Allocates an array (of the given size) of KeyDogPair* objects // and returns a pointer to it. // Also initializes each element of the array // to a pointer to a "Null Dog" (see the Dog class for "Null Dog"). KeyDogPair** constructHashTable(int hashTableSize); // Returns an integer that is the mapped value of the given key, // computed as follows: // -- the key is a string // -- the map is: // -- compute the sum of the ASCII values of the characters in the string // (just add up the characters, like they were integers) // -- return the sum mod hashTableSize. int hashMap(char* key, int hashTableSize); // Inserts the given Dog pointer into the given hashTable, // using the Dog's name as the key // and using hashMap as the mapping function. // Returns 0 if the insertion replaces a "Null Dog" // (see the Dog class for "Null Dog"), // else returns -1 (indicating a collision). int insert(Dog* dog, KeyDogPair** hashTable, int hashTableSize); #endif /* DOGMAP_H_ */