-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.c
More file actions
35 lines (29 loc) · 878 Bytes
/
dictionary.c
File metadata and controls
35 lines (29 loc) · 878 Bytes
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
/****************************************************************************
* dictionary.c
*
* Application Security, Assignment 1
*
* Adapted from code written by Ben Halperin.
***************************************************************************/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "dictionary.h"
// Hash table is an array of linked lists.
node* hashtable[HASH_SIZE];
// Maps a word to an integer value to place it in the hash table.
// Sum the value of each character in the word, then find the
// remainder after dividing by the size of the hash table.
int hash_function(const char* word)
{
int sum = 0;
int word_length = strlen(word);
for (int i = 0; i < word_length; i++)
{
sum += word[i];
}
int bucket = sum % HASH_SIZE;
return bucket;
}