def __get_switch_cases_info(TriggerMap): L = len(TriggerMap) sum_interval_size = [0] * (L + 1) sum_drop_out_interval_size = [0] * (L + 1) i = 0 for interval, target in TriggerMap: i += 1 sum_interval_size[i] = sum_interval_size[i - 1] sum_drop_out_interval_size[i] = sum_drop_out_interval_size[i - 1] if target.drop_out_f: sum_drop_out_interval_size[i] += interval.size() else: sum_interval_size[i] += interval.size() switch_case_range_list = [] p = 0 while p < L: # Count from the back, so the longest is treated first. # Thus, if there is a 'p' for a given 'q' where the criteria # holds for a switch case, then the 'p' is the best one, in the # sense that it is the largest interval. q_found = None for q in xrange(L - 1, p, -1): if solution.get(TriggerMap[p:q+1], size_all_intervals = sum_interval_size[q] - sum_interval_size[p], size_all_drop_out_intervals = sum_drop_out_interval_size[q] - sum_drop_out_interval_size[p]) \ == solution.E_Type.SWITCH_CASE: switch_case_range_list.append((p, q)) q_found = q break # If there was a switch case range, that step over it to the next if q_found: p = q_found p += 1 return switch_case_range_list
def __get_switch_cases_info(TriggerMap): L = len(TriggerMap) sum_interval_size = [0] * (L+1) sum_drop_out_interval_size = [0] * (L+1) i = 0 for interval, target in TriggerMap: i += 1 sum_interval_size[i] = sum_interval_size[i-1] sum_drop_out_interval_size[i] = sum_drop_out_interval_size[i-1] if target.drop_out_f: sum_drop_out_interval_size[i] += interval.size() else: sum_interval_size[i] += interval.size() switch_case_range_list = [] p = 0 while p < L: # Count from the back, so the longest is treated first. # Thus, if there is a 'p' for a given 'q' where the criteria # holds for a switch case, then the 'p' is the best one, in the # sense that it is the largest interval. q_found = None for q in xrange(L-1, p, -1): if solution.get(TriggerMap[p:q+1], size_all_intervals = sum_interval_size[q] - sum_interval_size[p], size_all_drop_out_intervals = sum_drop_out_interval_size[q] - sum_drop_out_interval_size[p]) \ == solution.E_Type.SWITCH_CASE: switch_case_range_list.append((p, q)) q_found = q break # If there was a switch case range, that step over it to the next if q_found: p = q_found p += 1 return switch_case_range_list
def __bisection(txt, TriggerMap): """Creates code for state transitions from this state. This function is very similar to the function creating code for a 'NumberSet' condition (see 'interval_handling'). Writes code that does a mapping according to 'binary search' by means of if-else-blocks. """ global LanguageDB T = len(txt) tip = solution.get(TriggerMap) # Potentially Recursive if tip == solution.E_Type.BISECTION: __get_bisection(txt, TriggerMap) # Direct Implementation / No more call to __bisection() elif tip == solution.E_Type.SWITCH_CASE: __get_switch(txt, TriggerMap) elif tip == solution.E_Type.COMPARISON_SEQUENCE: __get_comparison_sequence(txt, TriggerMap) elif tip == solution.E_Type.TRANSITION: __get_transition(txt, TriggerMap[0], IndentF=True) else: assert False # (*) Indent by four spaces (nested blocks are correctly indented) # delete the last newline, to prevent additional indentation LanguageDB.INDENT(txt, Start=T)
def __bisection(txt, TriggerMap): """Creates code for state transitions from this state. This function is very similar to the function creating code for a 'NumberSet' condition (see 'interval_handling'). Writes code that does a mapping according to 'binary search' by means of if-else-blocks. """ global LanguageDB T = len(txt) tip = solution.get(TriggerMap) # Potentially Recursive if tip == solution.E_Type.BISECTION: __get_bisection(txt, TriggerMap) # Direct Implementation / No more call to __bisection() elif tip == solution.E_Type.SWITCH_CASE: __get_switch(txt, TriggerMap) elif tip == solution.E_Type.COMPARISON_SEQUENCE: __get_comparison_sequence(txt, TriggerMap) elif tip == solution.E_Type.TRANSITION: __get_transition(txt, TriggerMap[0], IndentF=True) else: assert False # (*) Indent by four spaces (nested blocks are correctly indented) # delete the last newline, to prevent additional indentation LanguageDB.INDENT(txt, Start=T)