Implement a program that spell-checks a file, a la the below, using a hash table.
$ ./speller texts/lalaland.txt
MISSPELLED WORDS
[...]
AHHHHHHHHHHHHHHHHHHHHHHHHHHHT
[...]
Shangri
[...]
fianc
[...]
Sebastian's
[...]
WORDS MISSPELLED:
WORDS IN DICTIONARY:
WORDS IN TEXT:
TIME IN load:
TIME IN check:
TIME IN size:
TIME IN unload:
TIME IN TOTAL:
The challenge now before you is to implement, in order, load
, hash
, size
, check
, and unload
as efficiently as possible using a hash table in such a way that TIME IN load
, TIME IN check
, TIME IN size
, and TIME IN unload
are all minimized.
- You may not alter
speller.c
orMakefile
. - You may alter
dictionary.c
(and, in fact, must in order to complete the implementations ofload
,hash
,size
,check
, andunload
), but you may not alter the declarations (i.e., prototypes) ofload
,hash
,size
,check
, orunload
. You may, though, add new functions and (local or global) variables todictionary.c
. - You may change the value of
N
indictionary.c
, so that your hash table can have more buckets. - You may alter
dictionary.h
, but you may not alter the declarations ofload
,hash
,size
,check
, orunload
. - Your implementation of
check
must be case-insensitive. In other words, iffoo
is in dictionary, thencheck
should return true given any capitalization thereof; none offoo
,foO
,fOo
,fOO
,fOO
,Foo
,FoO
,FOo
, andFOO
should be considered misspelled. - Capitalization aside, your implementation of
check
should only returntrue
for words actually in dictionary. Beware hard-coding common words (e.g., the), lest we pass your implementation adictionary
without those same words. Moreover, the only possessives allowed are those actually indictionary
. In other words, even iffoo
is indictionary
,check
should returnfalse
givenfoo's
iffoo's
is not also indictionary
. - You may assume that any
dictionary
passed to your program will be structured exactly like ours, alphabetically sorted from top to bottom with one word per line, each of which ends with\n
. You may also assume thatdictionary
will contain at least one word, that no word will be longer thanLENGTH
(a constant defined indictionary.h
) characters, that no word will appear more than once, that each word will contain only lowercase alphabetical characters and possibly apostrophes, and that no word will start with an apostrophe. - You may assume that
check
will only be passed words that contain (uppercase or lowercase) alphabetical characters and possibly apostrophes. - Your spell checker may only take
text
and, optionally,dictionary
as input. Although you might be inclined (particularly if among those more comfortable) to “pre-process” our default dictionary in order to derive an “ideal hash function” for it, you may not save the output of any such pre-processing to disk in order to load it back into memory on subsequent runs of your spell checker in order to gain an advantage. - Your spell checker must not leak any memory. Be sure to check for leaks with
valgrind
. - You may search for (good) hash functions online, so long as you cite the origin of any hash function you integrate into your own code.
Full instructions available here