Commit 990678ff authored by Tres Seaver's avatar Tres Seaver

Scrap the '_set_operation' mega-function.

parent 2bb7a9d6
......@@ -1136,71 +1136,6 @@ class TreeSet(_Tree):
_p_resolveConflict = _Tree._p_resolveConflict
def _set_operation(s1, s2,
usevalues1=False, usevalues2=False,
w1=1, w2=1,
c1=True, c12=True, c2=True):
MERGE_DEFAULT = getattr(s1, 'MERGE_DEFAULT', None)
i1 = _SetIteration(s1, usevalues1, MERGE_DEFAULT)
i2 = _SetIteration(s2, usevalues2, MERGE_DEFAULT)
merge = i1.useValues or i2.useValues
MERGE = getattr(s1, 'MERGE', None)
if merge:
MERGE_WEIGHT = getattr(s1, 'MERGE_WEIGHT')
if MERGE is None and c12 and i1.useValues and i2.useValues:
raise TypeError("invalid set operation")
if (not i1.useValues) and i2.useValues:
t = i1; i1 = i2; i2 = t
t = w1; w1 = w2; w2 = t
t = c1; c1 = c2; c2 = t
if MERGE_DEFAULT is None:
if i1.useValues:
if (not i2.useValues) and c2:
raise TypeError("invalid set operation")
else:
if c1 or c12:
raise TypeError("invalid set operation")
r = s1._mapping_type()
def copy(i, w):
r._keys.append(i.key)
r._values.append(MERGE_WEIGHT(i.value, w))
else:
r = s1._set_type()
def copy(i, w):
r._keys.append(i.key)
while i1.active and i2.active:
cmp_ = cmp(i1.key, i2.key)
if cmp_ < 0:
if c1:
copy(i1, w1)
i1.advance()
elif cmp_ == 0:
if c12:
r._keys.append(i1.key)
if merge:
r._values.append(MERGE(i1.value, w1, i2.value, w2))
i1.advance()
i2.advance()
else:
if c2:
copy(i2, w2)
i2.advance()
if c1:
while i1.active:
copy(i1, w1)
i1.advance()
if c2:
while i2.active:
copy(i2, w2)
i2.advance()
return r
class set_operation(object):
def __init__(self, func, set_type):
......@@ -1214,7 +1149,6 @@ class set_operation(object):
def difference(set_type, o1, o2):
if o1 is None or o2 is None:
return o1
#return _set_operation(o1, o2, 1, 0, 1, 0, 1, 0, 0)
i1 = _SetIteration(o1, True, 0)
i2 = _SetIteration(o2, False, 0)
if i1.useValues:
......@@ -1246,7 +1180,6 @@ def union(set_type, o1, o2):
return o2
if o2 is None:
return o1
#return _set_operation(o1, o2, 0, 0, 1, 1, 1, 1, 1)
i1 = _SetIteration(o1, False, 0)
i2 = _SetIteration(o2, False, 0)
result = o1._set_type()
......@@ -1277,7 +1210,6 @@ def intersection(set_type, o1, o2):
return o2
if o2 is None:
return o1
#return _set_operation(o1, o2, 0, 0, 1, 1, 0, 1, 0)
i1 = _SetIteration(o1, False, 0)
i2 = _SetIteration(o2, False, 0)
result = o1._set_type()
......@@ -1302,7 +1234,6 @@ def weightedUnion(set_type, o1, o2, w1=1, w2=1):
return w2, o2
if o2 is None:
return w1, o1
#return 1, _set_operation(o1, o2, 1, 1, w1, w2, 1, 1, 1)
MERGE_DEFAULT = getattr(o1, 'MERGE_DEFAULT', None)
i1 = _SetIteration(o1, True, MERGE_DEFAULT)
i2 = _SetIteration(o2, True, MERGE_DEFAULT)
......@@ -1352,7 +1283,6 @@ def weightedIntersection(set_type, o1, o2, w1=1, w2=1):
return w2, o2
if o2 is None:
return w1, o1
#result = _set_operation(o1, o2, 1, 1, w1, w2, 0, 1, 0)
MERGE_DEFAULT = getattr(o1, 'MERGE_DEFAULT', None)
i1 = _SetIteration(o1, True, MERGE_DEFAULT)
i2 = _SetIteration(o2, True, MERGE_DEFAULT)
......
Markdown is supported
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