-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstractHashTable.h
67 lines (53 loc) · 1.89 KB
/
abstractHashTable.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
/*
* abstractHashTable.h
*
* Header file for a hash table that uses strings as keys
* and stores pointers to arbitrary structures as values
*
* Created by Sally Goldin on 5 March 2012 for CPE 113
*/
#ifndef ABSTRACTHASHTABLE_H
#define ABSTRACTHASHTABLE_H
/* Return the number of slots in the hash table.
*/
int hashTableSize();
/* Return the number of items currently stored in the hash table.
*/
int hashTableItemCount();
/* Initialize the hash table.
* Arguments
* size - How many slots in the table
* Must be 1 or greater. We assume the caller
* has checked this.
* hashFunction - Function that takes a string and returns an int
* which will be the index into the table.
* Returns 1 if successful, 0 if some error occurred.
*/
int hashTableInit(int size, unsigned int (*hashFunction)(char* key));
/* Free the hash table.
*/
void hashTableFree();
/* Insert a value into the hash table.
* Arguments
* key - character string key
* data - data to store in the table
* pCollision - set to true if there was a collision storing
* the data, else false
* Returns true (1) unless hash table has not been initialized or
* we can't allocate memory, in which case returns false (0)
*/
int hashTableInsert(char* key, void* data,int* pCollision);
/* Remove a value from the hash table.
* Arguments
* key - character string key
* Returns the data removed, or NULL if it is not found or table not init'd .
*/
void* hashTableRemove(char* key);
/* Look up a value in the hash table.
* Arguments
* key - character string key
* Returns the data associated with the key, or NULL if
* data associated with the key is not found.
*/
void* hashTableLookup(char* key);
#endif