How to access Structure info from map?

I am trying to create a hash map and i do not know how to access entry from openAddressTable

1
2
3
4
5
6
7
8
9
10
11
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_;
};
class HashTables{
private:
  std::unordered_map<unint,openBucket> openAddressTable;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//this obviously doesnt work
void HashTables::addToOpenAddress(unint inputHash, std::string text){
	/*auto it = openAddressTable.begin();
	int i = 0;
	openCollisions = 0;
	while (it != openAddressTable.end()) {
		if (it->second->entry_ == text) {
			inputHash++;
			openCollisions++;
			it->second->first = true;
			addToOpenAddress(inputHash, text);
		}
		else {
			it.insert(std::pair<unint, string>(inputHash, text);
		}
	}*/
	auto it = openAddressTable.begin();
	int size = openAddressTable.size();
	for (int i = 0; i < size; i++) {
		if () {

		}
	}

Last edited on
now i think you do it like this

1
2
3
4
5
6
7
int size = openAddressTable.size();
	for (int i = 0; i < size; i++) {
		if (openAddressTable[i].entry_==text) {
			openAddressTable[i].collision = true;
			i++;
		}
	}

So how do i create a new bucket?
1
2
3
4
else {
			openAddressTable.insert =  new openBucket;
			openAddressTable[i].entry_ = text;
		}
?
Last edited on
Topic archived. No new replies allowed.