-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhashtable.h
More file actions
55 lines (44 loc) · 1.29 KB
/
Copy pathhashtable.h
File metadata and controls
55 lines (44 loc) · 1.29 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
//
// hashtable.h
// Simple C Hash Table
//
// Header
//
// Simple Hash Table implementation with linked lists. Create a hashtable with a specified size, and:
// - add key/value
// - update key/value
// - delete key
// - print all key/values
//
// Created by Blake Caldwell on 12/15/13.
// Copyright (c) 2013 Blake Caldwell. All rights reserved.
//
#include <stdbool.h>
#ifndef Practice_MyHashTable_h
#define Practice_MyHashTable_h
// linked list
struct hLinkedList
{
char *key;
char *value;
struct hLinkedList *next;
};
// hashtable
struct hashTable
{
unsigned int size;
struct hLinkedList **lists;
};
// create a hashtable - return 0 on failure
int createHashTable(unsigned int size, struct hashTable **hashTable);
// destroy a hashtable - return 0 on failure
int destroyHashTable(struct hashTable **ht);
// add a string to the hashtable - return 0 on failure
int addToHashTable(struct hashTable *hashTable, char *key, char *value);
// remove a string to the hashtable - return 0 on failure
int removeFromHashTable(struct hashTable *hashTable, char *key);
// return whether we found the key
int valueForKeyInHashTable(struct hashTable *hashTable, char *key, char **value);
// print all keys and values in a hashtable
int printAllKeysAndValues(struct hashTable *hashTable);
#endif