Exemplo n.º 1
0
 def _combine_interval_interval(cls, set1, set2):
     if set1.range_type.is_subset(set2.range_type):
         min_val = set1.lowest if set2.lowest not in set1 else max(set1.lowest, set2.lowest)
         max_val = set1.highest if set2.highest not in set1 else min(set1.highest, set2.highest)
         return sets.IntervalSetPy(set1.range_type, min_val, max_val)
     elif set2.range_type.is_subset(set1.range_type):
         min_val = set2.lowest if set1.lowest not in set2 else max(set2.lowest, set1.lowest)
         max_val = set2.highest if set1.highest not in set2 else min(set2.highest, set1.highest)
         return sets.IntervalSetPy(set2.range_type, min_val, max_val)
     else:
         return sets.FiniteSetPy([])
Exemplo n.º 2
0
 def _combine_interval_finiteset(cls, set1, set2):
     final_sets = []
     intersecting_elems = SetIntersect(set1, set2).elems()
     if len(intersecting_elems) == 0:
         return set1
     # All intersecting elements are in an interval set, implies is orderable
     next_lowest = set1.lowest
     for next_highest in [set1.lowest] + sorted(intersecting_elems) + [set1.highest]:
         final_sets.append(sets.IntervalSetPy(set1.range_type, next_lowest, next_highest))
     return reduce(
         lambda accum, new: SetUnion(accum, new),
         final_sets,
         sets.FiniteSetPy([])
     )
Exemplo n.º 3
0
 def _combine_interval_interval(cls, set1, set2):
     difference_range_type = universes.UniverseDifference(set1.range_type, set2.range_type)
     normal_intervals = []
     difference_interval = None
     if set2.lowest > set1.highest or set2.highest < set1.lowest:
         return set1
     # now guaranteed to be some intersection between set1 and set2
     if set2.lowest <= set1.lowest and set2.highest <= set1.highest:
         normal_intervals.append(sets.IntervalSetPy(set1.range_type, set2.highest, set1.highest))
         difference_interval = sets.IntervalSetPy(difference_range_type, set1.lowest, set2.highest)
     elif set2.lowest <= set1.lowest and set2.highest > set1.highest:
         difference_interval = sets.IntervalSetPy(difference_range_type, set1.lowest, set1.highest)
     elif set2.lowest > set1.lowest and set2.highest <= set1.highest:
         normal_intervals.append(sets.IntervalSetPy(set1.range_type, set1.highest, set2.lowest))
         difference_interval = sets.IntervalSetPy(difference_range_type, set2.lowest, set2.highest)
         normal_intervals.append(sets.IntervalSetPy(set1.range_type, set2.highest, set1.highest))
     elif set2.lowest > set1.lowest and set2.highest > set1.highest:
         difference_interval = sets.IntervalSetPy(difference_range_type, set1.lowest, set2.lowest)
         normal_intervals.append(sets.IntervalSetPy(set1.range_type, set2.lowest, set1.highest))
     # make sure one is subset of another
     if set1.range_type.is_subset(set2.range_type):
         # discard difference interval, set2 removes everything in it
         return reduce(
             lambda accum, new: SetUnion(accum, new),
             normal_intervals,
             sets.FiniteSetPy([])
         )
     elif set2.range_type.is_subset(set1.range_type):
         # set2 is proper subset of set1, keep difference interval
         return reduce(
             lambda accum, new: SetUnion(accum, new),
             normal_intervals + [difference_interval],
             sets.FiniteSetPy([])
         )
     else:
         return set1
Exemplo n.º 4
0
 def _combine_finiteset_uniqueunion(cls, set1, set2):
     return sets.FiniteSetPy([x for x in set1.elems() if x not in set2])
Exemplo n.º 5
0
 def _combine_finiteset_interval(cls, set1, set2):
     return sets.FiniteSetPy([x for x in set1.elems() if x not in set2])
Exemplo n.º 6
0
 def _combine_uniqueunion_uniqueunion(cls, set1, set2):
     return reduce(
         lambda accum, new: SetUnion(accum, SetIntersect(set2, new)),
         set1.sets_ls,
         sets.FiniteSetPy([])
     )
Exemplo n.º 7
0
 def _combine_finiteset_finiteset(cls, set1, set2):
     return sets.FiniteSetPy([x for x in set1.elems() if x in set2])
Exemplo n.º 8
0
 def _combine_finiteset_finiteset(cls, set1, set2):
     return sets.FiniteSetPy(set1.elems() + set2.elems())