Question: I have a DAG in a JSON format, where each node is an entry: it has a name, and two arrays. One array is for other nodes with arrows coming into it, another array for nodes that this node is directed towards (outgoing arrows).

So, for example: 

```
{ 
  'id': 'A',   
  'connected_from' : ['B','C'],  
  'connects_to' : ['D','E']
}

```

And I have a collection of these nodes, that all together form a DAG. 

I'd like to map the nodes to a struct to hold these nodes, where the id is simply a string, and I'd like the arrays to be vectors of pointers of this struct: 

```
struct node { 
    string id;  
    vector<node*> connected_from;
    vector<node*> connected_to;
}

```

How do I convert the node entries as 'id' in the arrays of the JSON to a pointer to the correct struct holding that node?

One obvious approach is to build a map of key-value pairs, where key = id, value = the pointer to the struct with that id, and do a lookup - but is there a better way?

Answer: 
no, given only the information that you've provided there isn't a better way: you need to build a map.

however, for single letter id's the map can possibly take the form of a simple array with e.g. 26 entries for the English alphabet.
There's going to be some container object holding all the nodes (otherwise you're going to leak them.) You could always scan over the container to find the nodes. But this will be inefficient - O(N^2) while a map lookup will be O(N log N ).

Though if you store the objects in sorted order in the container (or use a sorted container) you can reduce both cases to O(N log N).

The constants will be different though, so for a small graph the scan may be faster.