I have the following struct:
array<int, 2> map_size;
struct Node{
int id;
array<int, 2> pos;
vector<Node*> nbs;
bool in_open;
bool in_closed;
};
Every Node has a position (pos) that is in range of map_size (global variable).
And I'm using the following unordered map
struct PosHash{
public:
size_t operator()(array<int, 2> const& pos) const{
return pos[1] + pos[0]*map_size[1];
}
};
struct PosCompare{
bool operator()(const array<int, 2>& pos1, const array<int, 2>& pos2) const{
if (pos1[0] == pos2[0] and pos1[1] == pos2[1]){
return true;
}
else{
return false;
}
}
};
unordered_map<array<int, 2>, Node*, PosHash, PosCompare> nodes;
map_size is a global variable used in the hash function and allows me to get a perfect hash. However, I would like to pass map_size as a parameter to PosHash and this way, avoid using global variables. How can I do this?
PD: map_size value is determined in execution time