From 0663c432764117c42e226d8cac623a9fcf3e8daf Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Wed, 13 Feb 2013 17:04:37 -0500 Subject: Parallelized plotting and parsing. --- parse/dir_map.py | 58 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'parse/dir_map.py') 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 from collections import defaultdict -class DirMap(object): - class Node(object): - def __init__(self, parent = None): - self.parent = parent - self.children = defaultdict(lambda : DirMap.Node(self)) - self.values = [] - - def heir(self, generation=1): - def heir2(node, generation): - if not generation: - return node - elif not node.children: - return None - else: - next_heir = node.children.values()[0] - return next_heir.heir(generation - 1) - return heir2(self, generation) - - def leafs(self, path=[], offset=0): - path = list(path) - check_node = self.heir(offset) - if check_node and check_node.children: - for child_name, child_node in self.children.iteritems(): - path += [child_name] - for leaf in child_node.leafs(path, offset): - yield leaf - path.pop() +class DirMapNode(object): + def __init__(self): + self.children = defaultdict(DirMapNode) + self.values = [] + + def heir(self, generation=1): + def heir2(node, generation): + if not generation: + return node + elif not node.children: + return None else: - yield (path, self) + next_heir = node.children.values()[0] + return next_heir.heir(generation - 1) + return heir2(self, generation) + + def leafs(self, path=[], offset=0): + path = list(path) + check_node = self.heir(offset) + if check_node and check_node.children: + for child_name, child_node in self.children.iteritems(): + path += [child_name] + for leaf in child_node.leafs(path, offset): + yield leaf + path.pop() + else: + yield (path, self) + +class DirMap(object): def __init__(self): - self.root = DirMap.Node(None) + self.root = DirMapNode() self.values = [] def add_values(self, path, values): -- cgit v1.2.2