1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 22:52:29 +08:00

experimental feature, algorithm/sorter.go try to implements sort function with go generics

This commit is contained in:
dudaodong
2022-01-14 17:01:44 +08:00
parent d46d12f949
commit 6f1feb96d6
5 changed files with 124 additions and 30 deletions

View File

@@ -5,31 +5,6 @@ import (
"reflect"
)
// func quickSort[T comparable](slice []T, low, high int) []T {
// if low < high {
// var p int
// slice, p = partitionForQuickSort(slice, low, high)
// slice = quickSort(slice, low, p-1)
// slice = quickSort(slice, p+1, high)
// }
// return slice
// }
// func partitionForQuickSort[T comparable](slice []T, low, high int) ([]T, int) {
// p := slice[high]
// i := low
// for j := low; j < high; j++ {
// //???, error: comparable don't support operator <
// if slice[j] < p {
// slice[i], slice[j] = slice[j], slice[i]
// i++
// }
// }
// slice[i], slice[high] = slice[high], slice[i]
// return slice, i
// }
// sliceValue return the reflect value of a slice
func sliceValue(slice interface{}) reflect.Value {
v := reflect.ValueOf(slice)