Commit eb6465ad authored by Martin Reinecke's avatar Martin Reinecke
Browse files

experimental union method for MultiFields

parent 4cb24a5d
...@@ -222,6 +222,35 @@ class MultiField(object): ...@@ -222,6 +222,35 @@ class MultiField(object):
res[key] = res[key]+val if key in res else val res[key] = res[key]+val if key in res else val
return MultiField.from_dict(res) return MultiField.from_dict(res)
def union(fields, domain=None):
"""Returns the union of its input fields
fields: iterable of MultiFields
The set of input fields. Their domains need not be identical,
but they must not be incompatible, e.g. by having different
DomainTuples for the same key.
domain: MultiDomain or None
If supplied, this mjst be the domain of the resulting field.
Providing this domain will accelerate the function.
The union of the input fields
If the same key occurs more than once in the input fields, the value
associated with the last occurrence will be put into the output.
No summation is performed!
res = {}
for field in fields:
return MultiField.from_dict(res, domain)
def flexible_addsub(self, other, neg): def flexible_addsub(self, other, neg):
if self._domain is other._domain: if self._domain is other._domain:
return self-other if neg else self+other return self-other if neg else self+other
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment