Skip to content
Snippets Groups Projects
Commit 19757276 authored by Ritesh Bansal's avatar Ritesh Bansal
Browse files

added comparison of trees

parent 7794c844
No related branches found
No related tags found
1 merge request!1Site structure
......@@ -45,9 +45,32 @@ class Trie:
# extract tree based on given timestamp
return self.root.extract(startTimestamp, endTimeStamp)
def comparison(self, tree1, tree2):
print()
def comparison(self, tree1):
# compare two trees
from collections import deque
stack_tree2 = deque()
stack_tree1 = deque()
stack_tree2.append(self.root)
stack_tree1.append(tree1)
while (len(stack_tree2) != 0):
tree2 = stack_tree2.pop()
tree = stack_tree1.pop()
for data in tree2.data:
if tree.data.__contains__(data):
if not tree.data[data] == tree2.data[data]:
return False
else:
return False
for child in tree2.children:
if tree.children.__contains__(child):
if not stack_tree2.__contains__(child):
stack_tree2.append(tree2.children[child])
stack_tree1.append(tree.children[child])
else:
return False
return True
def main():
......
......@@ -47,6 +47,10 @@ for dayData in data_train:
vtTree = sitemapURLS['www.vt.edu']
vtTreeCopy = vtTree.extract('20140906125541','20141215204723')
result = vtTree.comparison(vtTreeCopy)
print(result)
result = vtTree.comparison(vtTree.root)
print(result)
print('done')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment