Added __eq__ to relation object
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@66 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
dda1dba1a4
commit
51745e8218
@ -45,3 +45,6 @@
|
||||
- Outer join methods simplified
|
||||
- Form to send a survey
|
||||
- Makefile to create .deb package
|
||||
|
||||
0.8
|
||||
- Added __eq__ to relation object, will compare ignoring order.
|
21
relation.py
21
relation.py
@ -335,6 +335,27 @@ class relation (object):
|
||||
newt.content.append(item)
|
||||
|
||||
return newt
|
||||
def __eq__(self,other):
|
||||
'''Returns true if the relations are the same, ignoring order of items.
|
||||
This operation is rather heavy, since it requires sorting and comparing.'''
|
||||
other=self.rearrange(other) #Rearranges attributes' order so can compare tuples directly
|
||||
if (self.__class__!=other.__class__)or(self.header!=other.header):
|
||||
return False #Both parameters must be a relation
|
||||
|
||||
#Comparing header
|
||||
if len(self.header.attributes) != len(other.header.attributes):
|
||||
return False #Not the same number of attributes -> not equals
|
||||
for i in self.header.attributes:
|
||||
if i not in other.header.attributes:
|
||||
return False #Non shared attribute
|
||||
|
||||
#comparing content
|
||||
if len(self.content) != len(other.content):
|
||||
return False #Not the same
|
||||
for i in self.content:
|
||||
if i not in other.content:
|
||||
return False
|
||||
return True
|
||||
|
||||
def __str__(self):
|
||||
'''Returns a string representation of the relation, can be printed with
|
||||
|
Loading…
x
Reference in New Issue
Block a user