DLFSTrees

Doubly linked filesystem trees are both a doubly linked tree and a
filesystem tree.  They can walk paths backwards.
This commit is contained in:
Bryan Schumaker 2010-11-10 08:24:02 -05:00
parent a45d18552b
commit 1d95aeeaf2
2 changed files with 42 additions and 8 deletions

View File

@ -91,3 +91,24 @@ class FSTree(Tree):
else:
self.insert(base + [file])
class DLFSTree(DLTree, FSTree):
def __init__(self):
DLTree.__init__(self)
FSTree.__init__(self)
def walk_path_backwards(self):
return sep.join( self.walk_backwards() )
def insert_path(self, base, file = None):
path = base.split(sep)
return self.insert_path_split(path, file)
def insert_path_split(self, base, file = None):
if file == None:
child = self.insert(base)
#return DLTree.insert(self, base)
else:
child = self.insert(base + [file])
#return DLTree.insert(self, base + [file])
return child

View File

@ -17,12 +17,25 @@ from libsaria import trees
# print path
tree = trees.DLTree()
#tree = trees.DLTree()
#n = tree.insert(["a", "b", "c", "d"])
#o = tree.insert(["a", "b", "c", "e"])
#p = tree.insert(["f", "g", "h", "i"])
#tree.disp()
#print n.walk_backwards()
#print o.walk_backwards()
#print p.walk_backwards()
tree = trees.DLFSTree()
n = tree.insert_path("/a/b/c/d")
o = tree.insert_path("/a/b/c/e")
p = tree.insert_path("/f/g/h/i")
for path in tree.walk_paths():
print path
print n.walk_path_backwards()
print o.walk_path_backwards()
print p.walk_path_backwards()
n = tree.insert(["a", "b", "c", "d"])
o = tree.insert(["a", "b", "c", "e"])
p = tree.insert(["f", "g", "h", "i"])
tree.disp()
print n.walk_backwards()
print o.walk_backwards()
print p.walk_backwards()