diff --git a/complexity b/complexity index a7224a1..106fe76 100644 --- a/complexity +++ b/complexity @@ -69,6 +69,14 @@ Notation allowed. So after extracting the wanted elements, it has to check if the new tuple was already added to the new relation. And this brings the complexity to O(|n|²). + + But the projection can also be used to "rearrange" fields, which + makes no sense in pure relational algebra, but can be usefull to make + two relations match (in fact it is used internally to make relations + match if they have the same fields in different order). In this case + there is no need to check if the tuple already exists, because it is + assumed that the relation was correct. This gives a complexity of + O(|n|) in the best case. 2. BINARY OPERATORS @@ -123,4 +131,5 @@ Notation 2.9 Join Same as above. -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file diff --git a/relational/relation.py b/relational/relation.py index 99e77a9..557d859 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -143,7 +143,7 @@ class relation (object): Will delete duplicate items If an empty list or no parameters are provided, returns None''' #Parameters are supplied in a list, instead with multiple parameters - if attributes[0].__class__ == list().__class__: + if isinstance(attributes[0],list): attributes=attributes[0] #Avoiding duplicated attributes @@ -153,6 +153,10 @@ class relation (object): attributes1.append(i) attributes=attributes1 + #If source and dest has the same number of attributes, we are just rearranging + #so we won't need to check for duplicated entries + attributes_same_count=len(attributes)==len(self.header.attributes) + ids=self.header.getAttributesId(attributes) if len(ids)==0: @@ -169,11 +173,9 @@ class relation (object): row=[] for j in ids: row.append(i[j]) - if row not in newt.content:#Avoids duplicated items - newt.content.append(row) + if attributes_same_count or row not in newt.content: + newt.content.append(row) return newt - - def rename(self,params): '''Operation rename. Takes a dictionary