hash table collision/insertion

I think i have the openAddress method working, but i am unsure of how to continue with the chaining one. I can't figure out how to access the members of the pointer list located in the bucket.

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
typedef unsigned int unint;

//this bucket is used by the open addressing table
struct openBucket{
  bool collision;//whether or not there was a collision at this field
  string entry_;
};

//this bucket is used by the seperate chaining table
struct chainBucket{
  bool collision;//whether or not there was a collision at this field
  List *bucketList;
};

class HashTables{
private:
  std::unordered_map<unint,openBucket> openAddressTable;
  std::unordered_map<unint,chainBucket> chainingTable;


void HashTables::addToOpenAddress(unint inputHash, std::string text){
	openCollisions = 0;
	int size = openAddressTable.size();
	for (int i = inputHash; i < size; i++) {
		if (openAddressTable[i].entry_==text) {
			openAddressTable[i].collision = true;
			i++;
			openCollisions++;
		}
		else {
			openAddressTable.insert =  new openBucket;
			openAddressTable[i].entry_ = text;
		}
	}
}

//TODO
// finish this function to add an element to the separate chaining table
// this tables tracks collisions with linked lists
// if a collision occurs,
// - edit collision boolean for current location
// - add to linked list
// else add new chainBucket to position
void HashTables::addToChaining(unint inputHash, std::string text){
	//int size = chainingTable.size();
	//for (int i = 0; i < size; i++) {
	//	if()
	//}
	std::list <int> ::iterator i;
	int size = chainingTable.size();
	for (int i = inputHash; i < size; i++) {
		auto it = chainingTable[i].bucketList.begin();
		if(chainingTable[i].bucketList)
	}
		
}
Topic archived. No new replies allowed.