nodes: 0, module; 1, function_definition; 2, function_name:_argsort_and_resolve_ties; 3, parameters; 4, block; 5, identifier:time; 6, identifier:random_state; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, while_statement; 12, return_statement; 13, comment:"""Like numpy.argsort, but resolves ties uniformly at random"""; 14, assignment; 15, assignment; 16, assignment; 17, comparison_operator:i < n_samples - 1; 18, block; 19, identifier:order; 20, identifier:n_samples; 21, call; 22, identifier:order; 23, call; 24, identifier:i; 25, integer:0; 26, identifier:i; 27, binary_operator:n_samples - 1; 28, expression_statement; 29, while_statement; 30, if_statement; 31, expression_statement; 32, identifier:len; 33, argument_list; 34, attribute; 35, argument_list; 36, identifier:n_samples; 37, integer:1; 38, assignment; 39, boolean_operator; 40, block; 41, comparison_operator:i + 1 != inext; 42, comment:# resolve ties randomly; 43, block; 44, assignment; 45, identifier:time; 46, identifier:numpy; 47, identifier:argsort; 48, identifier:time; 49, keyword_argument; 50, identifier:inext; 51, binary_operator:i + 1; 52, comparison_operator:inext < n_samples; 53, comparison_operator:time[order[i]] == time[order[inext]]; 54, expression_statement; 55, binary_operator:i + 1; 56, identifier:inext; 57, expression_statement; 58, identifier:i; 59, identifier:inext; 60, identifier:kind; 61, string:"mergesort"; 62, identifier:i; 63, integer:1; 64, identifier:inext; 65, identifier:n_samples; 66, subscript; 67, subscript; 68, augmented_assignment; 69, identifier:i; 70, integer:1; 71, call; 72, identifier:time; 73, subscript; 74, identifier:time; 75, subscript; 76, identifier:inext; 77, integer:1; 78, attribute; 79, argument_list; 80, identifier:order; 81, identifier:i; 82, identifier:order; 83, identifier:inext; 84, identifier:random_state; 85, identifier:shuffle; 86, subscript; 87, identifier:order; 88, slice; 89, identifier:i; 90, identifier:inext
code: def _argsort_and_resolve_ties(time, random_state):
          """Like numpy.argsort, but resolves ties uniformly at random"""
          n_samples = len(time)
          order = numpy.argsort(time, kind="mergesort")
  
          i = 0
          while i < n_samples - 1:
              inext = i + 1
              while inext < n_samples and time[order[i]] == time[order[inext]]:
                  inext += 1
  
              if i + 1 != inext:
                  # resolve ties randomly
                  random_state.shuffle(order[i:inext])
              i = inext
          return order