From 19ac2aaacdf0a31cfa59e585286c8624252afd2f Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 26 Nov 2010 09:12:34 +0000 Subject: [PATCH] - Set hash method for the classes git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@265 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational/parser.py | 2 ++ relational/relation.py | 7 ++++++- relational/rtypes.py | 4 +++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 282419f..92f9c47 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ - Fixed optimization involving selection and parenthesis in the expression (Rev 260) - Fixed futile_union_intersection_subtraction optimization that didn't work when selection operator was in the left subtree (Rev 261) - Module parallel does something, can execute queries in parallel +- Set hash method for the classes 0.11 - Font is set only on windows (Rev 206) diff --git a/relational/parser.py b/relational/parser.py index 04319a1..cc3c184 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -51,6 +51,7 @@ class node (object): This class is used to convert an expression into python code.''' kind=None + __hash__=None def __init__(self,expression=None): '''Generates the tree from the tokenized expression @@ -186,6 +187,7 @@ class node (object): 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 diff --git a/relational/relation.py b/relational/relation.py index 230fdfc..6475fd2 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -25,6 +25,8 @@ class relation (object): A relation can be represented using a table Calling an operation and providing a non relation parameter when it is expected will result in a None value''' + __hash__=None + def __init__(self,filename=""): '''Creates a relation, accepts a filename and then it will load the relation from that file. If no parameter is supplied an empty relation is created. Empty @@ -185,7 +187,6 @@ class relation (object): if (newt.header.rename(old,new)) == False: return None - #TODO only copy the link and mark the new relation as read only newt.content=self.content newt._readonly=True return newt @@ -511,9 +512,13 @@ class header (object): '''This class defines the header of a relation. It is used within relations to know if requested operations are accepted''' + #Since relations are mutalbe we explicitly block hashing them + __hash__=None + def __init__(self,attributes): '''Accepts a list with attributes' names. Names MUST be unique''' self.attributes=attributes + def __repr__(self): return "header(%s)" % (self.attributes.__repr__()) diff --git a/relational/rtypes.py b/relational/rtypes.py index 8727251..0f38bf4 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -53,7 +53,9 @@ class rdate (object): self.month=self.intdate.month self.weekday=self.intdate.weekday() self.year=self.intdate.year - + + def __hash__(self): + return self.intdate.__hash__() def __str__(self): return self.intdate.__str__() def __add__(self,days):