It sounds to me like you want everything :D
Don't worry, this is not a bad thing. At all.
In this case, you need a fast access container on top
of a doubly linked list, as suggested above. However,
there are a couple of other things I'd like to point out.
I assume that your CCoordinates represent
waypoints of a route or something like that.
If you build/analyze each route separately and a
waypoint can't be the starting point of more than
one connections, you can just do something like this:
1 2 3 4 5 6 7 8 9 10 11
|
class CCoordinate
{
// coordinate attributes
// this -> next connection attributes
CCoordinate * mNext_;
CCoordinate * mPrevious_;
};
std::map<KeyType, CCoordinate *> my_route;
|
That is, build an intrusive list out of waypoints
(this saves you a whole level of indirection)
and use a map to index it. KeyType could be
a string, an int, or anything you think you'll
be using more often to access the waypoints.
If a waypoint can be the starting point of more than one
connections, you can't use an intrusive list for them.
You can do that for the connections though if they are
guaranteed not to belong to more than one routes.
In this case, CConnect instances should hold pointers
to waypoints. Note that you don't need to hold both
points in a connection, since point B of one connection
will always be point A of the next connection in the list:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class CCoordinate
{
// coordinate attributes
};
class CConnect
{
CCoordinate * mPoint_;
// this -> next connection attributes
CConnect * mNext_;
CConnect * mPrevious_;
};
std::map<CoordKeyType, CCoordinate *> my_points;
std::map<ConnKeyType, CConnect *> my_route;
|
Using a reference to CCoordinate is not a good choice, because
you can't rebind a reference to another object after you initialize it.
I'm sure that you can figure out how you should lay things
out if a connection can be part of many different routes.
Oh, and something else. If the number of the elments stored in your map
is really big, a hashmap could be a better choice. I guess you could try both
std::map and a hashmap and see which one performs better in your case.