Use lists for partial content

So conversion to set is done only once.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2020-08-15 09:17:23 +02:00
parent 683ff6f26d
commit 519cc35b18
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF

View File

@ -118,7 +118,7 @@ class Relation(NamedTuple):
except: except:
raise Exception('Failed to compile expression: %s' % expr) raise Exception('Failed to compile expression: %s' % expr)
content = set() content = []
for i in self.content: for i in self.content:
# Fills the attributes dictionary with the values of the tuple # Fills the attributes dictionary with the values of the tuple
attributes = {attr: i[j].autocast() attributes = {attr: i[j].autocast()
@ -127,7 +127,7 @@ class Relation(NamedTuple):
try: try:
if eval(c_expr, attributes): if eval(c_expr, attributes):
content.add(i) content.append(i)
except Exception as e: except Exception as e:
raise Exception( raise Exception(
"Failed to evaluate %s\n%s" % (expr, e.__str__())) "Failed to evaluate %s\n%s" % (expr, e.__str__()))
@ -277,7 +277,7 @@ class Relation(NamedTuple):
# Non shared ids of the other relation # Non shared ids of the other relation
noid = [i for i in range(len(other.header)) if i not in oid] noid = [i for i in range(len(other.header)) if i not in oid]
content = set() content = []
for i in self.content: for i in self.content:
# Tuple partecipated to the join? # Tuple partecipated to the join?
added = False added = False
@ -289,12 +289,12 @@ class Relation(NamedTuple):
if match: if match:
item = chain(i, (j[l] for l in noid)) item = chain(i, (j[l] for l in noid))
content.add(tuple(item)) content.append(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 = chain(i, repeat(Rstring('---'), len(noid))) item = chain(i, repeat(Rstring('---'), len(noid)))
content.add(tuple(item)) content.append(tuple(item))
return Relation(header, frozenset(content)) return Relation(header, frozenset(content))
@ -320,7 +320,7 @@ class Relation(NamedTuple):
# Non shared ids of the other relation # Non shared ids of the other relation
noid = [i for i in range(len(other.header)) if i not in oid] noid = [i for i in range(len(other.header)) if i not in oid]
content = set() content = []
for i in self.content: for i in self.content:
for j in other.content: for j in other.content:
match = True match = True
@ -329,7 +329,7 @@ class Relation(NamedTuple):
if match: if match:
item = chain(i, (j[l] for l in noid)) item = chain(i, (j[l] for l in noid))
content.add(tuple(item)) content.append(tuple(item))
return Relation(header, frozenset(content)) return Relation(header, frozenset(content))