diff options
| author | Ajax <commial@gmail.com> | 2016-01-25 10:50:59 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-01-25 14:28:41 +0100 |
| commit | 418d2f1600dd1b7dbe81537f9b24c1d4e2d450cb (patch) | |
| tree | aaaf354d02efc3463beed062f5ad55397be91879 /miasm2/core | |
| parent | b4d46020aff6aac57b79cfcb64011bdc608854d9 (diff) | |
| download | miasm-418d2f1600dd1b7dbe81537f9b24c1d4e2d450cb.tar.gz miasm-418d2f1600dd1b7dbe81537f9b24c1d4e2d450cb.zip | |
Graph; introduce copy and merge
Diffstat (limited to 'miasm2/core')
| -rw-r--r-- | miasm2/core/graph.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py index f38f71d6..ee5dc418 100644 --- a/miasm2/core/graph.py +++ b/miasm2/core/graph.py @@ -26,6 +26,25 @@ class DiGraph(object): def edges(self): return self._edges + def merge(self, graph): + """Merge the current graph with @graph + @graph: DiGraph instance + """ + for node in graph._nodes: + self.add_node(node) + for edge in graph._edges: + self.add_edge(*edge) + + def __add__(self, graph): + """Wrapper on `.merge`""" + self.merge(graph) + return self + + def copy(self): + """Copy the current graph instance""" + graph = self.__class__() + return graph + self + def __eq__(self, graph): if not isinstance(graph, self.__class__): return False |