From 04e3b8e3169a74929b618a6ebf284b8eab778898 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 1 May 2009 14:45:31 +0000 Subject: [PATCH] added __eq__ method to the tree git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@147 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/relational/optimizer.py b/relational/optimizer.py index 454345c..14399e8 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -61,7 +61,17 @@ class node (object): return pass + def __eq__(self,other): + if not (isinstance(other,node) and self.name==other.name and self.kind==other.kind): + return False + if self.kind==UNARY: + if other.prop!=self.prop: + return False + return self.child==other.child + if self.kind==BINARY: + return self.left==other.left and self.right==other.right + return True def __str__(self): if (self.kind==RELATION): return self.name @@ -182,6 +192,7 @@ if __name__=="__main__": #a= tokenize("(a - (a ᑌ b) * π a,b (a-b)) - ρ 123 (a)") #a= tokenize(u"π a,b (a*b)") #a=tokenize("(a-b*c)*(b-c)") + print tree("σ i==2 (c ᑌ d - (aᑎb))") == tree("σ i==3 (c ᑌ d - (aᑎb))") a=general_optimize("σ i==2 (c ᑌ d - (aᑎb))") #a=general_optimize("σ i==2 (σ b>5 (d))") print a