It sounds like what you really want is an std::multimap
(or std::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 a std::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.