<commit_before>package main

import "./help"


func merge_sort(arr []int,l int, r int) []int{
	
	if l >= r{
		return nil
	}
	mid := r + (l - r) / 2
	merge_sort(arr, l, mid + 1)
	merge_sort(arr,mid, r)
	arr = merge(arr, l, mid, r)
	return arr
}


func merge(arr []int, l int, mid int, r int)[] int{

	aux := arr
	i, j := l, mid + 1
	for k := i; k <= r; k ++ {
		switch {
			case i > mid: 
				arr[k] =  aux[j - l]
				j ++
			case j > r:
				arr[k] = aux[i - l]
				i ++
			case aux[i - l] > aux[j - l] :
				arr[k] = arr[i - l]
				i ++
			default:
				arr[k] = arr[j - l]
				j ++ 

		}
	}
	return arr

}

func sort(arr []int, n int) []int{
	merge_sort(arr, 0, n - 1)
	return nil
}
func main(){

	arr := help.GenRanArray(10000, 1, 9999)
	help.TestSort(sort)(arr, len(arr))
}

<commit_msg>修复go版本 merge_sort bug<commit_after>package main

import (
	"./help"
)

func merge_sort(arr []int, l int, r int) {

	if l >= r {
		return
	}
	mid := l + (r-l)/2
	merge_sort(arr, l, mid)
	merge_sort(arr, mid+1, r)
	merge(arr, l, mid, r)
}

func merge(arr []int, l int, mid int, r int) {
	// copy 临时array
	aux := make([]int, r-l + 1)
	copy(aux,arr[l : r+1])

	i, j := l, mid+1
	for k := l; k < r+1; k++ {
		if i > mid {
			arr[k] = aux[j-l]
			j++
		} else if j > r {
			arr[k] = aux[i-l]
			i++
		} else if aux[i-l] < aux[j-l] {
			arr[k] = aux[i-l]
			i++
		} else {
			arr[k] = aux[j-l]
			j++
		}
	}

}

func sort(arr []int, n int) []int {
	merge_sort(arr, 0, n-1)
	return arr
}

func main() {
	arr := help.GenRanArray(1000000, 1, 999999)
	//help.ArrayPrint(arr)
	help.TestSort(sort)(arr, len(arr))
	//help.ArrayPrint(arr)

}
{'fraction_non_alphanumeric': 0.20247678018575851, 'fraction_numerical': 0.022910216718266253, 'mean_word_length': 2.416490486257928, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2734326', 'n_tokens_mistral': 862, 'n_tokens_neox': 774, 'n_words': 210}