Replace intermediate lists with iterators
Some more intermediate lists created during joins are now not created in favour of iterators instead
This commit is contained in:
parent
f974fc316d
commit
d05c2e2d3c
@ -297,7 +297,7 @@ class relation (object):
|
|||||||
newt.header = header(list(self.header.attributes))
|
newt.header = header(list(self.header.attributes))
|
||||||
|
|
||||||
# Adds all the attributes of the 2nd, when non shared
|
# Adds all the attributes of the 2nd, when non shared
|
||||||
for i in other.header.attributes:
|
for i in other.header:
|
||||||
if i not in shared:
|
if i not in shared:
|
||||||
newt.header.attributes.append(i)
|
newt.header.attributes.append(i)
|
||||||
# Shared ids of self
|
# Shared ids of self
|
||||||
@ -306,10 +306,7 @@ class relation (object):
|
|||||||
oid = other.header.getAttributesId(shared)
|
oid = other.header.getAttributesId(shared)
|
||||||
|
|
||||||
# Non shared ids of the other relation
|
# Non shared ids of the other relation
|
||||||
noid = []
|
noid = [i for i in range(len(other.header)) if i not in oid]
|
||||||
for i in range(len(other.header.attributes)):
|
|
||||||
if i not in oid:
|
|
||||||
noid.append(i)
|
|
||||||
|
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
# Tuple partecipated to the join?
|
# Tuple partecipated to the join?
|
||||||
@ -320,17 +317,13 @@ class relation (object):
|
|||||||
match = match and (i[sid[k]] == j[oid[k]])
|
match = match and (i[sid[k]] == j[oid[k]])
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
item = list(i)
|
item = chain(i,(j[l] for l in noid))
|
||||||
for l in noid:
|
|
||||||
item.append(j[l])
|
|
||||||
|
|
||||||
newt.content.add(tuple(item))
|
newt.content.add(tuple(item))
|
||||||
added = True
|
added = True
|
||||||
# If it didn't partecipate, adds it
|
# If it didn't partecipate, adds it
|
||||||
if not added:
|
if not added:
|
||||||
item = list(i)
|
item = chain(i,repeat('---',len(noid)))
|
||||||
for l in range(len(noid)):
|
|
||||||
item.append("---")
|
|
||||||
newt.content.add(tuple(item))
|
newt.content.add(tuple(item))
|
||||||
|
|
||||||
return newt
|
return newt
|
||||||
@ -340,8 +333,7 @@ class relation (object):
|
|||||||
shared attributes, it will behave as cartesian product.'''
|
shared attributes, it will behave as cartesian product.'''
|
||||||
|
|
||||||
# List of attributes in common between the relations
|
# List of attributes in common between the relations
|
||||||
shared = list(set(self.header.attributes)
|
shared = set(self.header).intersection(set(other.header))
|
||||||
.intersection(set(other.header.attributes)))
|
|
||||||
|
|
||||||
newt = relation() # Creates the new relation
|
newt = relation() # Creates the new relation
|
||||||
|
|
||||||
@ -548,6 +540,9 @@ class header (object):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.attributes)
|
return iter(self.attributes)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.attributes)
|
||||||
|
|
||||||
def getAttributesId(self, param):
|
def getAttributesId(self, param):
|
||||||
'''Returns a list with numeric index corresponding to field's name'''
|
'''Returns a list with numeric index corresponding to field's name'''
|
||||||
return [self.attributes.index(i) for i in param]
|
return [self.attributes.index(i) for i in param]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user