コード例 #1
0
ファイル: sort_test.go プロジェクト: camlistore/go4
func TestStringsWithSwapper(t *testing.T) {
	data := strings
	With(len(data), reflectutil.Swapper(data[:]), func(i, j int) bool {
		return data[i] < data[j]
	})
	if !StringsAreSorted(data[:]) {
		t.Errorf("sorted %v", strings)
		t.Errorf("   got %v", data)
	}
}
コード例 #2
0
ファイル: sort_test.go プロジェクト: camlistore/go4
func BenchmarkStableInt1K_WithSwapper(b *testing.B) {
	b.StopTimer()
	unsorted := make([]int, 1<<10)
	for i := range unsorted {
		unsorted[i] = i ^ 0x2cc
	}
	data := make([]int, len(unsorted))
	for i := 0; i < b.N; i++ {
		copy(data, unsorted)
		b.StartTimer()
		Stable(MakeInterface(len(data), reflectutil.Swapper(data), func(i, j int) bool {
			return data[i] < data[j]
		}))
		b.StopTimer()
	}
}
コード例 #3
0
ファイル: sort_test.go プロジェクト: camlistore/go4
func BenchmarkSortString1K_WithSwapper(b *testing.B) {
	b.StopTimer()
	unsorted := make([]string, 1<<10)
	for i := range unsorted {
		unsorted[i] = strconv.Itoa(i ^ 0x2cc)
	}
	data := make([]string, len(unsorted))

	for i := 0; i < b.N; i++ {
		copy(data, unsorted)
		b.StartTimer()
		With(len(data), reflectutil.Swapper(data), func(i, j int) bool {
			return data[i] < data[j]
		})
		b.StopTimer()
	}
}
コード例 #4
0
ファイル: sort.go プロジェクト: camlistore/go4
// SliceSorter returns a sort.Interface to sort the provided slice
// using the provided less function.
// If the provided interface is not a slice, the function panics.
func SliceSorter(slice interface{}, less func(i, j int) bool) Interface {
	return MakeInterface(reflect.ValueOf(slice).Len(), reflectutil.Swapper(slice), less)
}