diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 13:27:43 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 13:27:43 +0100 |
| commit | 44e930b71107310eae55060cf0aa2cac7089d239 (patch) | |
| tree | 2b5c1cc62bc51a87d75393a80053ffe85db043cb /sort | |
| parent | 390333bb314f6cb25adc5716ea383112860ed342 (diff) | |
fortune not found
Quick commit
Diffstat (limited to 'sort')
| -rw-r--r-- | sort/quick.go | 4 | ||||
| -rw-r--r-- | sort/sort_test.go | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/sort/quick.go b/sort/quick.go index f58f046..5dbcfe5 100644 --- a/sort/quick.go +++ b/sort/quick.go @@ -31,13 +31,13 @@ func quickPartition(a ds.ArrayList, lo, hi int) int { v := a[lo] // Partitioning item for { - for i++; a[i].Lower(v); i++ { + for i++; a[i] < v; i++ { if i == hi { break } } - for j--; v.Lower(a[j]); j-- { + for j--; v < a[j]; j-- { if j == lo { break } diff --git a/sort/sort_test.go b/sort/sort_test.go index 899669b..fa515d7 100644 --- a/sort/sort_test.go +++ b/sort/sort_test.go @@ -10,8 +10,9 @@ import ( var benchResult ds.ArrayList var benchResultInt []int -const minLength int = 100 -const maxLength int = 10000 +const minLength int = 1 +const maxLength int = 1000000 +const maxSlowLength int = 100000 var arrayListCache map[string]ds.ArrayList @@ -19,13 +20,13 @@ type sortAlgorithm func(ds.ArrayList) ds.ArrayList type sortAlgorithmInt func([]int) []int func TestSelectionSort(t *testing.T) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { test(Selection, i, t) } } func TestInsertionSort(t *testing.T) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { test(Insertion, i, t) } } @@ -82,13 +83,13 @@ func TestShuffleSort(t *testing.T) { } func BenchmarkInsertionSort(b *testing.B) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { benchmark(Insertion, i, b) } } func BenchmarkSelectionSort(b *testing.B) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { benchmark(Selection, i, b) } } @@ -204,6 +205,7 @@ func makeRandomIntegers(length, max int) ds.ArrayList { return a } a := ds.RandomIntegers(length, max) + a = Shuffle(a) arrayListCache[key] = a return a } |
