I have an object Line which contains 2 objects of type Point called Point1 and Point2. I want to create a HashMap containing lines and whose keys are std::pair<Point1, Point2>.
What I’d like to do is find all the Lines with are referenced (for instance) by Point1, i.e. with key std::pair<Point1, Anything>. I don’t care about std::pair<Anything, Point1>.
I don’t know if it’s possible or not, I hope it is.
Thanks
It sounds like what you really want is an
std::multimap(orstd::unordered_multimap), with individual points as the keys, and lines (pair<point, point>) as the associated values. Alternatively, since the key holds the first point, you this could be done as astd::multimap<point, point>, to avoid storing Point1 twice, once as the key and again as part of the associated value. Either way it’s easy to look up all the lines that use a particular point.Another possibility (if the collection of lines is reasonably static) would be to put your line objects into a vector, sorted by Point1. This (again) lets you search quickly for all the lines that include a particular point. The advantage would be that this reduces the amount of data you need to store (eliminates the pointers between nodes), and generally improve search speed. The disadvantage is that inserting or deleting items is relatively slow.