-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Vect merge sort #334
base: master
Are you sure you want to change the base?
Add Vect merge sort #334
Conversation
This looks like insertion sort to me. |
The following works: export
sortBy : {n : Nat} -> (elem -> elem -> Ordering) -> Vect n elem -> Vect n elem
sortBy _ [] = []
sortBy _ [x] = [x]
sortBy order xs with (parity n)
sortBy {n = j + j} order xs | Even =
let (left, right) = splitAt j xs in
mergeBy order (sortBy order left) (sortBy order right)
sortBy {n = S (j + j)} order xs | Odd =
let (left, right) = splitAt (S j) xs in
mergeBy order (sortBy order left) (sortBy order right)
where
data Parity : Nat -> Type where
Even : {n : _} -> Parity (n + n)
Odd : {n : _} -> Parity (S (n + n))
parity : (n:Nat) -> Parity n
parity 0 = Even {n = Z}
parity (S k) with (parity k)
parity (S (j + j)) | Even {n = j} = Odd
parity (S (S (j + j))) | Odd {n = j} =
rewrite (plusSuccRightSucc j j) in Even {n = S j} |
Sorry I got confused because this uses the existing |
This would be good to have, but it is indeed insertion sort. I'll merge once it's updated. |
@edwinb updated in what way? You mean you would prefer a merge sort rather than an insertion sort? |
I think merge sort would be better, yes, just for the generally better performance - I think that is what you intended though isn't it? |
No, I just needed a sort on Vect but I can have a go at merge sort if I have time, good learning. |
I've added a merge sort and left the insertion sort but changed the default to merge sort. |
No description provided.