-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymtable.h
101 lines (62 loc) · 2.72 KB
/
symtable.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Library for creating and using Symbol tables */
#ifndef SYMTABLE_INCLUDE
#define SYMTABLE_INCLUDE
#include <stdio.h>
typedef void* SymTable_T;
/* Creates a SymTable struct with no bindings.
Asserts: if memory was allocated succesfully for oSymTable at runtime. */
SymTable_T SymTable_new(void);
/* Frees all memory used by oSymTable.
Parameters:
* oSymTable: a SymTable_T type */
void SymTable_free(SymTable_T oSymTable);
/* Returns the number of bindings in oSymTable.
Asserts: if oSymTable is not NULL at runtime.
Parameters:
* oSymTable: a SymTable_T type */
unsigned int SymTable_getLength(SymTable_T oSymTable);
/* Creates a new binding for oSymTable from a given pcKey and pvValue.
Asserts:
1) if oSymTable and pcKey are not NULL at runtime.
2) if necessary memory was allocated succesfully at runtime.
Parameters:
* oSymTable: a SymTable_T type
* pcKey: a character array (key). Must be null terminated.
* pvValue: pointer to any value */
void SymTable_put(SymTable_T oSymTable, const char *pcKey, const void *pvValue);
/* Removes a binding with key equal to pcKey.
Asserts: if oSymTable and pcKey are not NULL at runtime.
Parameters:
* oSymTable: a SymTable_T type
* pcKey: a character array (key). Must be null terminated.
Returns: 1 if removal was successful, 0 if such binding was not found */
int SymTable_remove(SymTable_T oSymTable, const char *pcKey);
/* Checks whether a binding with key equal to pcKey is present in oSymTable.
Asserts: if oSymTable and pcKey are not NULL at runtime.
Parameters:
* oSymTable: a SymTable_T type.
* pcKey: character array (key). Must be null terminated.
Returns: 1 if pcKey is found, 0 otherwise */
int SymTable_contains(SymTable_T oSymTable, const char *pcKey);
/* Finds in oSymTable a binding with key equal to pcKey.
Asserts: if oSymTable and pcKey are not NULL at runtime.
Parameters:
* oSymTable: a SymTable_T type
* pcKey: a character array (key). Must be null terminated.
Returns: a pointer to the value or NULL if such binding was not found. */
void* SymTable_get(SymTable_T oSymTable, const char *pcKey);
/* Applies function pfApply to every binding in oSymTable.
Asserts: if oSymTable and pfApply are not NULL at runtime.
Parameters:
* oSymTable: a SymTable_T type
* pfApply: function to apply
* pvExtra: a pointer to any value. Used by pfApply. */
void SymTable_map(SymTable_T oSymTable,
void (*pfApply)(const char *pcKey, void *pvValue, void *pvExtra),
const void *pvExtra);
/* Prints basic information about the hashtable:
1) Max bindings in a bucket.
2) Min binding in a bucket.
3) Weighted average bucket size */
void SymTable_stats(SymTable_T oSymTable);
#endif