Since the DAG’s edges hold data, they better have their own identifiers, just like the nodes.

That is, the json representation should be composed of three components:

  1. Node records: mapping each node identifier to the node’s data.
  2. Edge records: mapping each edge identifier to the edge’s data.
  3. Adjacency lists: mapping each node identifier to an array of edge identifiers, each corresponds to an edge going out of the node.
DAG = {
  "adjacency": {
    "a": ["1", "2"],
    "b": ["3"]
  },
  "nodes": {
    "a": {
      // data
    },
    "b": {
      // data
    },
    "c": {
      // data
    }
  },
  "edges": {
    "1": {
      "from": "a", "to": "b",
      "data": {
        // data
      }
    },
    "2": {
      "from": "a", "to": "b",
      "data": {
        // data
      }
    },
    "3": {
      "from": "b", "to": "c",
      "data": {
        // data
      }
    }
  }
}

Leave a Reply