diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-13 17:04:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-13 17:04:37 -0500 |
commit | 0663c432764117c42e226d8cac623a9fcf3e8daf (patch) | |
tree | cd36aed08c5f30b28ee29ea0e29da304947ff052 /parse/dir_map.py | |
parent | 0c28870f3f9dd5fe3c029a63ab4149de5f2beb59 (diff) |
Parallelized plotting and parsing.
Diffstat (limited to 'parse/dir_map.py')
-rw-r--r-- | parse/dir_map.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/parse/dir_map.py b/parse/dir_map.py index 11c872a..1c17f40 100644 --- a/parse/dir_map.py +++ b/parse/dir_map.py | |||
@@ -4,38 +4,38 @@ import re | |||
4 | 4 | ||
5 | from collections import defaultdict | 5 | from collections import defaultdict |
6 | 6 | ||
7 | class DirMap(object): | 7 | class DirMapNode(object): |
8 | class Node(object): | 8 | def __init__(self): |
9 | def __init__(self, parent = None): | 9 | self.children = defaultdict(DirMapNode) |
10 | self.parent = parent | 10 | self.values = [] |
11 | self.children = defaultdict(lambda : DirMap.Node(self)) | 11 | |
12 | self.values = [] | 12 | def heir(self, generation=1): |
13 | 13 | def heir2(node, generation): | |
14 | def heir(self, generation=1): | 14 | if not generation: |
15 | def heir2(node, generation): | 15 | return node |
16 | if not generation: | 16 | elif not node.children: |
17 | return node | 17 | return None |
18 | elif not node.children: | ||
19 | return None | ||
20 | else: | ||
21 | next_heir = node.children.values()[0] | ||
22 | return next_heir.heir(generation - 1) | ||
23 | return heir2(self, generation) | ||
24 | |||
25 | def leafs(self, path=[], offset=0): | ||
26 | path = list(path) | ||
27 | check_node = self.heir(offset) | ||
28 | if check_node and check_node.children: | ||
29 | for child_name, child_node in self.children.iteritems(): | ||
30 | path += [child_name] | ||
31 | for leaf in child_node.leafs(path, offset): | ||
32 | yield leaf | ||
33 | path.pop() | ||
34 | else: | 18 | else: |
35 | yield (path, self) | 19 | next_heir = node.children.values()[0] |
20 | return next_heir.heir(generation - 1) | ||
21 | return heir2(self, generation) | ||
22 | |||
23 | def leafs(self, path=[], offset=0): | ||
24 | path = list(path) | ||
25 | check_node = self.heir(offset) | ||
26 | if check_node and check_node.children: | ||
27 | for child_name, child_node in self.children.iteritems(): | ||
28 | path += [child_name] | ||
29 | for leaf in child_node.leafs(path, offset): | ||
30 | yield leaf | ||
31 | path.pop() | ||
32 | else: | ||
33 | yield (path, self) | ||
34 | |||
35 | class DirMap(object): | ||
36 | 36 | ||
37 | def __init__(self): | 37 | def __init__(self): |
38 | self.root = DirMap.Node(None) | 38 | self.root = DirMapNode() |
39 | self.values = [] | 39 | self.values = [] |
40 | 40 | ||
41 | def add_values(self, path, values): | 41 | def add_values(self, path, values): |