diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2026-05-29 19:59:02 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2026-05-29 22:18:03 -0700 |
| commit | cec51d4ddac2cd0e943cec254abb51a70dab7251 (patch) | |
| tree | 7b6c186145c08fd6a4b1f4903543310adde4e47a | |
| parent | 74d4e78bfca0abe6b4fbc1fce61d47192344febb (diff) | |
| download | sixel-cec51d4ddac2cd0e943cec254abb51a70dab7251.tar.zst | |
Make quickSelect generic
| -rw-r--r-- | sixel.go | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -37,7 +37,7 @@ func lcg(state *uint64) int { return int(s >> 33) } -func partition(a []color.RGBA, lo, hi, pivotIndex int, cmp func(color.RGBA, color.RGBA) int) (int, int) { +func partition[S ~[]E, E any](a S, lo, hi, pivotIndex int, cmp func(E, E) int) (int, int) { pivot := a[pivotIndex] lt := lo eq := lo @@ -58,7 +58,7 @@ func partition(a []color.RGBA, lo, hi, pivotIndex int, cmp func(color.RGBA, colo return lt, gt } -func quickSelect(list []color.RGBA, k int, cmp func(color.RGBA, color.RGBA) int, randState *uint64) { +func quickSelect[S ~[]E, E any](list S, k int, cmp func(E, E) int, randState *uint64) { left, right := 0, len(list)-1 for { if left == right { |
