diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-04-07 16:53:43 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:03 +0200 |
commit | a7ca40bfe1c3ca86e239574a01d958e4eba751ee (patch) | |
tree | ae57deb8b8de1c2db5e41938d2d602f93f03d50e /monkey | |
parent | b203887ecb557a02f4df7c47c2f46ee5dedb140e (diff) |
Add a couple of utility functions to Node
Diffstat (limited to 'monkey')
-rw-r--r-- | monkey/graph.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/monkey/graph.py b/monkey/graph.py index 3e1d3a2..cbe44f7 100644 --- a/monkey/graph.py +++ b/monkey/graph.py @@ -20,6 +20,19 @@ class Node(object): target.ein.append(self) return target + # Return a list of nodes in [self]. + def preorder(self): + nodes = [self] + for n in self.eout: + nodes += n.preorder() + return nodes + + # Return a one-line string representation of [self]. + def __str__(self): + return '(' + str(self.data) + ' ' + \ + ' '.join([str(c) if c.eout else '"'+str(c.data)+'"' for c in self.eout]) + \ + ')' + def __repr__(self): return str(self.data) |