-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwf_table.h
More file actions
66 lines (56 loc) · 2 KB
/
wf_table.h
File metadata and controls
66 lines (56 loc) · 2 KB
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
#ifndef WF_TABLE_H
#define WF_TABLE_H
/**
* hashcode: stored to save computations during hash_rehash
*/
typedef struct wf_item{
char *word;
int count;
double freq;
unsigned long hashcode;
struct wf_item *next;
} wf_item;
typedef struct wf_table {
char *file_name;
int no_words;
int no_entries;
int no_rows;
/** y used to decide when to rehash, in an attempt to maintain O(y) lookup time */
double y;
wf_item **data;
wf_item **list;
struct wf_table *next;
} wf_table;
/**
* takes in a string makes a hashcode for it
* RETURN: the hashcode generated from the string
*/
unsigned long hash_func(char *);
/**
* takes in a hashtable and the word to be inserted
* RETURN: EXIT_FAILURE if malloc failed, else EXIT_SUCCESS;
* */
int hash_insert(wf_table *, char *);
/**
* takes in a hashtable and will attempt to rehash, moving entries into a larger 2x row size array
* returns EXIT_FAILURE if malloc failed
*/
int hash_rehash(wf_table *);
/**
* only use when you no longer want a hashtable at all. hash_rehash will do the job of freeing the space of the old hashtable without destroying the entries
* note, it will not only destroy all entries and the hashtable itself, but also all the strings in the hashtable as well
*/
int hash_destroy(wf_table *);
/**
* actually computes the frequencies for words, which can only be done once we are finished adding words in
*/
int hash_comp_freq(wf_table *);
/** creates the hashtable with a filename, a y value, and a number of starting rows */
/** RETURN: either a hashtable or NULL on the condition of malloc failure */
wf_table *hash_create_table(char *, int, double);
/** look for the word in the hashtable. return frequency of word. returns 0 if not found */
double hash_get(wf_table *, char *);
/** will create a lexicographically sorted list for use in the later analysis phase */
int hash_lexical_list(wf_table *);
int wf_item_comparator(const void *, const void *);
#endif