-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTableVoid.h
More file actions
52 lines (40 loc) · 1.22 KB
/
HashTableVoid.h
File metadata and controls
52 lines (40 loc) · 1.22 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
//
// Hash Table
//
#include <assert.h>
#include <stdlib.h>
#include <string.h>
// Each hash entry stores a key, object pair
struct HashTableVoidEntry {
const char * _key;
void * _data;
HashTableVoidEntry * _next;
};
// This is a Hash table that maps string keys to objects of type Data
class HashTableVoid {
public:
// Number of buckets
enum { TableSize = 2039};
// Array of the hash buckets.
HashTableVoidEntry **_buckets;
// Obtain the hash code of a key
int hash(const char * key);
public:
HashTableVoid();
// Add a record to the hash table. Returns true if key already exists.
// Substitute content if key already exists.
bool insertItem( const char * key, void * data);
// Find a key in the dictionary and place in "data" the corresponding record
// Returns false if key is does not exist
bool find( const char * key, void ** data);
// Removes an element in the hash table. Return false if key does not exist.
bool removeElement(const char * key);
};
class HashTableVoidIterator {
int _currentBucket;
HashTableVoidEntry *_currentEntry;
HashTableVoid * _hashTable;
public:
HashTableVoidIterator(HashTableVoid * hashTable);
bool next(const char * & key, void * & data);
};