I have a std::unordered_multimap that is defined as:
typedef std::unordered_multimap<Index, Point> PointMap;
Where Index is a struct defined as:
struct Index {
int i, j, k;
};
And Point is also a struct defined as:
struct Point {
int x, y, z;
long distanceSq(const Point& p) const;
};
I am trying to define a function that will hash a given Point and return an Index as the key for the std::unordered_multimap. In order to do that however, I need to use a variable D that is part of a class called StarCounter. It is defined as:
class StarCounter {
std::vector<Point> stars;
int N;
int D;
long Dsq;
public:
StarCounter (int n, int d, std::istream& in);
long countPairs();
private:
long rangeCount (const Point& star, const PointMap& cubes);
Index getCubeIndex(const Point& star) const;
};
Now ideally, the getCubeIndex() function returns exactly what I want to hash:
Index StarCounter::getCubeIndex(const Point& star) const
{
Index result{star.x / D,
star.y / D,
star.z / D};
return result;
}
Because it returns an Index and my std::unordered_multimap has key vales that are Index's; such that I can do mymm[i, j, k].
However, since the StarCounter class has no hash function in its definition, and I am unable to add one (yes this is for practice), I cannot seem to call D or getCubeIndex() from say:
Index starHash(const Point& star) {
return getCubeIndex(star); // because StarCounter::starHash isnt defined
}
or
Index starHash(const Point& star) {
Index ind {
star.x / D, // D is a member of StarCounter, again not callable
star.y / D,
star.z / D,
};
}
Am I going about this the wrong way for hashing the Point to return an Index key value?
Aucun commentaire:
Enregistrer un commentaire