Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
Help on module btree: NAME btree FILE /home/tonym/workspace/plug-test/tonym/btree.py DESCRIPTION btree.py. Represent btree in python with subtree test. Usage: from tonym import btree io = TreeIO() (tree,subtree) = io.parse(file('tree.txt')) tree.contains(subtree) OVERVIEW: Create binary tree in python. tree stored using Node class with children in python list nodes are indexed in a hashtable (dict) of the node positions. This allows for O(1)-time lookup of subtree root nodes BUGS: * duplicate nodes clobber index and break lookup TODO: * make Node & Index private CLASSES App Index Node Tree TreeIO class App | Contains app globals like tree root and main method | | Methods defined here: | | run(self, args) class Index | hashtable index of node data -> node in tree | | Methods defined here: | | __init__(self) | create new index with index in dict | | __setitem__(self, k, v) | | add(self, data, node) | add data->node ref | | contains(self, data) | | get(self, data) class Node | Contains node data and refs to children. Also, ref to index | | Methods defined here: | | __init__(self, data, index) | | __str__(self) | | append(self, data) | add child left, right. raise error if full | | complete(self) | return if the current node has both children | | contains(self, qnode) | look up root node in index. Then recursive compare to children | qnode is the root node of the query subtree | | iterNodes(self, root=True) | iterate over nodes breadth-first | | printNodes(self) class Tree | Binary tree with dictionary index of node entries | usage | t = Tree() | t.append() | for e in t: | print e | | Methods defined here: | | __init__(self) | | __iter__(self) | | append(self, data) | | contains(self, other) class TreeIO | Parses csv representation of tree & subtree into two trees | returns tuple (tree(Tree), subtree(Tree)) | | Methods defined here: | | build(self, tree_list) | build tree from ordered list representation | | parse(self, f) | read file f and build into tree FUNCTIONS debug(s) debug logging DATA DEBUG = False __author__ = 'firstname.lastname@example.org' __version__ = '1.0.0' VERSION 1.0.0 AUTHOR email@example.com Help on module grid: NAME grid FILE /home/tonym/workspace/plug-test/tonym/grid.py DESCRIPTION grid.py Read grid from file and print out path in serpentine pattern Usage: from tonym import btree io = GridIO() grid = io.build(file('grid.txt')) l = grid.clockwise() pprint(l) OVERVIEW: My thoughts here were to treat this as a pathfinding problem. The "map" would be stored in a dict of coordinate tuples, i.e. (x,y) -> data. Nodes are deleted when visited Deleting nodes from a dict is easier to manage than nested lists The nodes could be traversed w,s,e,n (clockwise) which is conceptually easier than an odd nested loop. Nodes will be removed from the map when visited CLASSES App Grid GridIO class App | Contains app globals | | Methods defined here: | | run(self, args) class Grid | Contains map as dict of tuples (x,y) -> data | | Methods defined here: | | __init__(self) | | clockwise(self) | return iterator of clockwise traversal | | get(self, coord) | get data at coord (tuple) | | iterEast(self, origin) | return iterator east from tuple origin | | iterNorth(self, origin) | return iterator north from tuple origin | | iterSouth(self, origin) | | iterWest(self, origin) | return iterator west from tuple origin | | set(self, coord, data) | set data on map for x,y class GridIO | parses file into grid | | Methods defined here: | | build(self, f) | read file f and build into tree DATA __author__ = 'firstname.lastname@example.org' __version__ = '1.0.0' VERSION 1.0.0 AUTHOR email@example.com