addGraph method

GraphSnapshot<V> addGraph(
  1. Graph<V> graph
)

Implementation

GraphSnapshot<V> addGraph(Graph<V> graph) {
  // Use amru statuses (a=added,m=modified,r=removed,u=unmodified)
  // Start with ar, assume u for remaining
  // Use edges to check for m

  // Added: Get all vertices that's in the graph but not this
  final added = Map.fromEntries(graph.vertices.entries
          .where((entry) => !vertices.containsKey(entry.key)))
      .map(VertexSnapshot.mapAsAdded);

  // Removed: In addition, there are never any removals
  final removed = <V, VertexSnapshot<V>>{};

  // Remaining: Get all vertices that's in this graph but not in added
  // Additionally, we initially treat them as unmodified
  final tempRemaining = Map.fromEntries(
          vertices.entries.where((entry) => !added.containsKey(entry.key)))
      .map(VertexSnapshot.mapAsUnmodified);

  // Modified: Get all verticies from remaining that have amr edges
  final modified = <V, VertexSnapshot<V>>{};

  // Unmodified: Get all vertices from remaining that is not modified
  // Additionally, these are already mapped as u from the step that created the remaining
  final unmodified = Map.fromEntries(tempRemaining.entries
      .where((entry) => !modified.containsKey(entry.key)));

  return GraphSnapshot._fromOperation(
      added: added,
      modified: modified,
      removed: removed,
      unmodified: unmodified);
}