-
-
Save anonymous/6c71126b2fcea6d81871683e6f8f3e48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* dictionary.h | |
* | |
* Computer Science 50 | |
* Problem Set 5 | |
* | |
* Declares a dictionary's functionality. | |
*/ | |
#ifndef DICTIONARY_H | |
#define DICTIONARY_H | |
#include <stdbool.h> | |
// maximum length for a word | |
// (e.g., pneumonoultramicroscopicsilicovolcanoconiosis) | |
#define LENGTH 45 | |
/** | |
* Returns true if word is in dictionary else false. | |
*/ | |
bool check(const char* word); | |
// count the number of words in dictionary | |
unsigned int count = 0; | |
/** | |
* Loads dictionary into memory. Returns true if successful else false. | |
*/ | |
bool load(const char* dictionary); | |
// define hash function | |
int hash_it(char* needs_hashing) | |
{ | |
unsigned int hash = 0; | |
for (int i = 0, n = strlen(needs_hashing); i<n; i++) hash = (hash << 2) ^ needs_hashing[i]; | |
return hash % HASHTABLE_SIZE; | |
} | |
// define node in hashtable | |
typedef struct node | |
{ | |
char word[LENGTH + 1]; | |
struct node* next = NULL; | |
} | |
node; | |
// define hash table | |
node* hashtable[65536]; | |
for (int i = 0; i < 65536; i++) hashtable[i] = NULL; | |
/** | |
* Returns number of words in dictionary if loaded else 0 if not yet loaded. | |
*/ | |
unsigned int size(void); | |
/** | |
* Unloads dictionary from memory. Returns true if successful else false. | |
*/ | |
bool unload(void); | |
#endif // DICTIONARY_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment