def _set_op(a_subtree, b_subtree, func1, func2): """Recursive function for performing set operations.""" a_nodes = set(a_subtree.keys()) b_nodes = set(b_subtree.keys()) floor = {} for node in func1(a_nodes, b_nodes): if node == 'lines': a_set = set(tuple(z) for z in a_subtree.get(node, [])) b_set = set(tuple(z) for z in b_subtree.get(node, [])) temp = func2(a_set, b_set) count.append(len(temp)) if temp != []: floor[node] = temp else: a_branch = a_subtree.get(node, {}) b_branch = b_subtree.get(node, {}) if not a_branch and b_branch: temp = a_branch if a_branch else b_branch count.append(count_lines(temp)) else: temp = _set_op(a_branch, b_branch, func1, func2) if temp != {}: floor[node] = temp return floor
def publish(self, tree): root_keys = {key: key for key in tree.data.keys()} m_keys = margin_vals(root_keys) item_counts = {} for key in root_keys: st = tree.touch(key) count = count_lines(st) item_counts[key] = count m_keys[key] += ' ' + str(count) for key, val in margin_vals(m_keys).iteritems(): print val, '#' * item_counts[key]