-
Notifications
You must be signed in to change notification settings - Fork 11
/
dictionary.h
95 lines (83 loc) · 2.38 KB
/
dictionary.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/****************************************************************************
* dictionary.h
*
* Application Security, Assignment 1
*
* Adapted from code written by Ben Halperin
***************************************************************************/
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <stdbool.h>
#include <stdio.h>
// maximum length for a word
// (e.g., pneumonoultramicroscopicsilicovolcanoconiosis)
#define LENGTH 45
#define HASH_SIZE 2000
#define MAX_MISSPELLED 1000
typedef struct node
{
char word[LENGTH + 1];
struct node* next;
}
node;
typedef node* hashmap_t;
/**
* Array misspelled is populated with words that are misspelled. Returns the length of misspelled.
*/
/**
* Inputs:
* fp: A file pointer to the document to check for spelling errors.
* hashtable: The hash table used to determine spelling
* misspelled: An empty char* array to be populated with misspelled words.
* This array will never be greater than 1000 words long.
*
* Returns:
* int: The number of words in the misspelled arary.
*
* Modifies:
* misspelled: This array will be filled with misspelled words.
*
* Example:
* int num_misspelled = check_words(text_file, hashtable, misspelled);
**/
int check_words(FILE* fp, hashmap_t hashtable[], char * misspelled[]);
/**
* Returns true if word is in dictionary else false.
*/
/**
* Inputs:
* word: A word to check the spelling of.
* hashtable: The hash table used to determine spelling
*
* Returns:
* bool: A boolean value indicating if the word was correctly spelled.
*
* Modifies:
*
* Example:
* bool correct = check_word(word, hashtable);
**/
bool check_word(const char* word, hashmap_t hashtable[]);
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
/**
* Inputs:
* dictionary_file: Path to the words file.
* hashtable: The hash table to be populated.
*
* Returns:
* bool: Whether or not the hashmap successfully populated.
*
* Modifies:
* hashtable: This hashmap should be filled with words from the file provided.
*
* Example:
* bool success = load_dictionary("wordlist.txt", hashtable);
**/
bool load_dictionary(const char* dictionary_file, hashmap_t hashtable[]);
/**
* Already implemented in dictionary.c
**/
int hash_function(const char* word);
#endif // DICTIONARY_H