Trees don't have values
Trees don't actually need a value. I can make a subclass later if I find it's important.
This commit is contained in:
parent
9c73996ade
commit
d15a4e2967
|
@ -3,15 +3,17 @@
|
||||||
from libsaria.path import sep
|
from libsaria.path import sep
|
||||||
|
|
||||||
class Tree(dict):
|
class Tree(dict):
|
||||||
def __init__(self, value = None):
|
def __init__(self):
|
||||||
#self.children = dict()
|
dict.__init__(self)
|
||||||
self.value = value
|
|
||||||
|
def __disp__(self, level):
|
||||||
|
return "%s (%s)", (child, self[child].value)
|
||||||
|
|
||||||
def disp(self, level = 0):
|
def disp(self, level = 0):
|
||||||
#children = self.children
|
|
||||||
for child in self:
|
for child in self:
|
||||||
space = " " * level
|
space = " " * level
|
||||||
print space, "%s (%s)" % (child, self[child].value)
|
fmt, vals = self.__disp__(level)
|
||||||
|
print space, fmt % vals
|
||||||
self[child].disp(level + 1)
|
self[child].disp(level + 1)
|
||||||
|
|
||||||
def walk(self):
|
def walk(self):
|
||||||
|
@ -26,18 +28,18 @@ class Tree(dict):
|
||||||
for res in child.walk():
|
for res in child.walk():
|
||||||
yield [key] + res
|
yield [key] + res
|
||||||
|
|
||||||
def insert(self, path, values=[]):
|
def __insert__(self, path):
|
||||||
path_part = path[0]
|
path_part = path[0]
|
||||||
value = path_part
|
child = self.get(path_part, None)
|
||||||
if len(values) > 0:
|
|
||||||
value = values[0]
|
|
||||||
values = values[1:]
|
|
||||||
child = self.get(path_part, None)
|
|
||||||
if child == None:
|
if child == None:
|
||||||
child = self.__class__(value)
|
child = self.__class__()
|
||||||
self[path_part] = child
|
self[path_part] = child
|
||||||
|
return child
|
||||||
|
|
||||||
|
def insert(self, path):
|
||||||
|
child = self.__insert__(path)
|
||||||
if len(path) > 1:
|
if len(path) > 1:
|
||||||
child.insert(path[1:], values)
|
child.insert(path[1:])
|
||||||
|
|
||||||
|
|
||||||
class FSTree(Tree):
|
class FSTree(Tree):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user