nodes: 0, module; 1, function_definition; 2, function_name:merge_intervals; 3, parameters; 4, block; 5, identifier:elems; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, expression_statement; 14, comment:# Freeze the interval to tuples; 15, return_statement; 16, identifier:overlap_thres; 17, float:2.0; 18, comment:"""
      Project in x axis
      Sort by start
      Go through segments and keep max x1
  
      Return a list of non-overlapping intervals
      """; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, identifier:e; 24, identifier:ordered; 25, block; 26, call; 27, call; 28, identifier:overlap_thres; 29, call; 30, identifier:ordered; 31, call; 32, identifier:intervals; 33, list; 34, identifier:cur; 35, list; 36, if_statement; 37, expression_statement; 38, attribute; 39, argument_list; 40, identifier:map; 41, argument_list; 42, identifier:max; 43, argument_list; 44, identifier:sorted; 45, argument_list; 46, unary_operator; 47, unary_operator; 48, comparison_operator:e.x0 - cur[1] > overlap_thres; 49, comment:# Check interval validity; 50, block; 51, assignment; 52, identifier:intervals; 53, identifier:append; 54, identifier:cur; 55, identifier:tuple; 56, identifier:intervals; 57, float:0.0; 58, identifier:overlap_thres; 59, identifier:elems; 60, keyword_argument; 61, identifier:overlap_thres; 62, identifier:overlap_thres; 63, binary_operator:e.x0 - cur[1]; 64, identifier:overlap_thres; 65, if_statement; 66, expression_statement; 67, continue_statement; 68, subscript; 69, call; 70, identifier:key; 71, lambda; 72, attribute; 73, subscript; 74, comparison_operator:cur[1] > 0.0; 75, block; 76, assignment; 77, identifier:cur; 78, integer:1; 79, identifier:max; 80, argument_list; 81, lambda_parameters; 82, attribute; 83, identifier:e; 84, identifier:x0; 85, identifier:cur; 86, integer:1; 87, subscript; 88, float:0.0; 89, expression_statement; 90, identifier:cur; 91, list; 92, subscript; 93, attribute; 94, identifier:e; 95, identifier:e; 96, identifier:x0; 97, identifier:cur; 98, integer:1; 99, call; 100, attribute; 101, attribute; 102, identifier:cur; 103, integer:1; 104, identifier:e; 105, identifier:x1; 106, attribute; 107, argument_list; 108, identifier:e; 109, identifier:x0; 110, identifier:e; 111, identifier:x1; 112, identifier:intervals; 113, identifier:append; 114, identifier:cur
code: def merge_intervals(elems, overlap_thres=2.0):
      """
      Project in x axis
      Sort by start
      Go through segments and keep max x1
  
      Return a list of non-overlapping intervals
      """
      overlap_thres = max(0.0, overlap_thres)
      ordered = sorted(elems, key=lambda e: e.x0)
  
      intervals = []
      cur = [-overlap_thres, -overlap_thres]
      for e in ordered:
          if e.x0 - cur[1] > overlap_thres:
              # Check interval validity
              if cur[1] > 0.0:
                  intervals.append(cur)
              cur = [e.x0, e.x1]
              continue
          cur[1] = max(cur[1], e.x1)
      intervals.append(cur)
      # Freeze the interval to tuples
      return map(tuple, intervals)