summaryrefslogtreecommitdiff
path: root/wk5/pset/speller/dictionary.c
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-04-29 03:12:33 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-04-29 03:12:33 +0000
commit1b991de1d0ba289fe1e175d2d373cb61e3cdeb65 (patch)
tree42afdf79c1fb6370a45b932d9528b888a349aa67 /wk5/pset/speller/dictionary.c
parent0d9f4f8189cf04378f2485d0b5f222a77f2dbb18 (diff)
Sun, Apr 28, 2024, 8:12 PM -07:00
Diffstat (limited to 'wk5/pset/speller/dictionary.c')
-rw-r--r--wk5/pset/speller/dictionary.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/wk5/pset/speller/dictionary.c b/wk5/pset/speller/dictionary.c
index c095ad4..74723ab 100644
--- a/wk5/pset/speller/dictionary.c
+++ b/wk5/pset/speller/dictionary.c
@@ -48,8 +48,13 @@ bool check(const char *word)
// Hashes word to a number
unsigned int hash(const char *word)
{
- // TODO: Improve this hash function
- return toupper(word[0]) - 'A';
+ // (sum of (letter - 'A') % 26) of a word to get a value of where to store it in the hash table
+ int val = 0;
+ for (int i = 0; word[i] != '\0'; i++)
+ {
+ val += toupper(word[i]) - 'A';
+ }
+ return val %= 26;
}
// Loads dictionary into memory, returning true if successful, else false