about summary refs log tree commit diff stats
path: root/html/002test.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 5490Kartik Agaram2019-07-271-3/+3
* 5485 - promote SubX to top-levelKartik Agaram2019-07-271-62/+70
* 4891Kartik Agaram2018-12-301-0/+1
* 4890 - new html renderingsKartik Agaram2018-12-291-16/+11
* 4814Kartik Agaram2018-12-011-31/+35
* 4539Kartik Agaram2018-09-071-8/+7
* 4447Kartik Agaram2018-07-271-86/+104
* 4239Kartik Agaram2018-05-081-7/+7
* 4199Kartik K. Agaram2018-01-251-22/+21
* 4162Kartik K. Agaram2017-12-221-111/+86
* 4161Kartik K. Agaram2017-12-151-8/+8
* 4155Kartik K. Agaram2017-12-071-1/+1
* 3971Kartik K. Agaram2017-08-191-86/+85
* 3927Kartik K. Agaram2017-06-191-2/+2
* 3897 - various updates to documentationKartik K. Agaram2017-05-291-1/+1
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-4/+5
* 3761Kartik K. Agaram2017-03-071-17/+18
* 3750Kartik K. Agaram2017-03-021-1/+1
* 3749Kartik K. Agaram2017-03-021-2/+2
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-17/+17
* 3710Kartik K. Agaram2016-12-261-112/+112
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-115/+139
* 3561Kartik K. Agaram2016-10-221-1/+1
* 3558Kartik K. Agaram2016-10-221-6/+6
* 3544Kartik K. Agaram2016-10-221-1/+1
* 3543Kartik K. Agaram2016-10-221-3/+2
* 3524Kartik K. Agaram2016-10-201-2/+2
* 3433Kartik K. Agaram2016-10-011-1/+1
* 3315Kartik K. Agaram2016-09-101-4/+6
* 3219Kartik K. Agaram2016-08-171-1/+1
* 3174Kartik K. Agaram2016-08-121-1/+1
* 3102Kartik K. Agaram2016-07-051-1/+1
* 2812Kartik K. Agaram2016-03-271-13/+22
* 2744Kartik K. Agaram2016-03-091-4/+4
* 2743Kartik K. Agaram2016-03-091-39/+31
* 2706 - update htmlKartik K. Agaram2016-02-251-4/+5
* 2175Kartik K. Agaram2015-09-061-1/+1
* 2062Kartik K. Agaram2015-08-231-25/+36
* 1949Kartik K. Agaram2015-08-061-22/+23
* 1885Kartik K. Agaram2015-07-291-22/+21
* 1853Kartik K. Agaram2015-07-251-21/+22
* 1690Kartik K. Agaram2015-07-011-1/+1
* 1632Kartik K. Agaram2015-06-231-1/+1
* 1631 - update html versionsKartik K. Agaram2015-06-231-5/+5
* 1556Kartik K. Agaram2015-06-121-1/+1
* 1549Kartik K. Agaram2015-06-091-2/+2
* 1517Kartik K. Agaram2015-05-301-3/+5
* 1461 - descriptions/table of contents for the layersKartik K. Agaram2015-05-261-1/+1
* 1459Kartik K. Agaram2015-05-251-6/+8
dify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. class Tree(object): def __init__(self, dictionary=None, parent=None, key=None): if dictionary is None: self._tree = dict() else: self._tree = dictionary self.key = key self.parent = parent def copy(self): """Create a deep copy""" def deep_copy_dict(dct): dct = dct.copy() for key, val in dct.items(): if isinstance(val, dict): dct[key] = deep_copy_dict(val) return dct newtree = Tree() if isinstance(self._tree, dict): newtree._tree = deep_copy_dict(self._tree) else: newtree._tree = self._tree return newtree def merge(self, other, copy=False): """Merge another Tree into a copy of self""" def deep_merge(branch, otherbranch): assert isinstance(otherbranch, dict) if not isinstance(branch, dict): branch = dict() elif copy: branch = branch.copy() for key, val in otherbranch.items(): if isinstance(val, dict): if key not in branch: branch[key] = None branch[key] = deep_merge(branch[key], val) else: branch[key] = val return branch if isinstance(self._tree, dict) and isinstance(other._tree, dict): content = deep_merge(self._tree, other._tree) elif copy and hasattr(other._tree, 'copy'): content = other._tree.copy() else: content = other._tree return type(self)(content) def set(self, keys, value, force=True): """Sets the element at the end of the path to <value>.""" if not isinstance(keys, (list, tuple)): keys = tuple(keys) if len(keys) == 0: self.replace(value) else: fnc = force and self.plow or self.traverse subtree = fnc(keys) subtree.replace(value) def unset(self, iterable): chars = list(iterable) first = True while chars: if first or isinstance(subtree, Tree) and subtree.empty(): top = chars.pop() subtree = self.traverse(chars) assert top in subtree._tree, "no such key: " + chr(top) del subtree._tree[top] else: break first = False def empty(self): return len(self._tree) == 0 def replace(self, value): if self.parent: self.parent[self.key] = value self._tree = value def plow(self, iterable): """Move along a path, creating nonexistant subtrees""" tree = self._tree last_tree = None char = None for char in iterable: try: newtree = tree[char] if not isinstance(newtree, dict): raise KeyError() except KeyError: newtree = dict() tree[char] = newtree last_tree = tree tree = newtree if isinstance(tree, dict): return type(self)(tree, parent=last_tree, key=char) else: return tree def traverse(self, iterable): """Move along a path, raising exceptions when failed""" tree = self._tree last_tree = tree char = None for char in iterable: last_tree = tree try: tree = tree[char] except TypeError: raise KeyError("trying to enter leaf") except KeyError: raise KeyError(repr(char) + " not in tree " + str(tree)) if isinstance(tree, dict): return type(self)(tree, parent=last_tree, key=char) else: return tree __getitem__ = traverse