I want to implement adjacency list for graph using unordered_map. Selecting unordered_map because it can give me O(1) time to access neighboring vertices by a given vertex. So my idea is to define the unordered_map as below:
using namespace std;
class node {};
class edge {};
typedef vector<edge*> edges_t;
typedef unordered_map<node*, edges_t*> graph_t;
I use the pointer of class node as the key of unordered_map because using node object directly would require a customized std::hash implementation. The major issue of using pointer is memory management. I need to free the allocated memory explicitly.
Can unique_ptr be used here to ease the memory managment? or any better solution to suggest ?
Thanks !
node
contain anedges_t
thingy? – n. 1.8e9-where's-my-share m.unordered_multimap
and ditch theedges_t
thingsy entirly – Valerij