I am writing a path finding algorithm, so I have TreeNode
that represents the nodes but in my algorithm, I have an open
container that is a priority_queue
, which allows fast retrieval of the highest priority node. I also need to check quickly if I already explored a given node, so I have a closed
container that is a set
.
Now the problem is: who owns what? where are my TreeNodes stored? The open
and closed
containers don't need to store the nodes themselves, they can just have a pointer to them, but where do I store the nodes then?
My idea is to store in these containers weak_ptr<TreeNode>
and when I want to create a new TreeNode I use make_shared<TreeNode>
? Or can I have a vector<TreeNode>
that stores all the nodes and the other containers just store indices, so I avoid costly shared_ptr
?