faster traversable sorting with the help of vector-algorithms#2
faster traversable sorting with the help of vector-algorithms#2mikeplus64 wants to merge 1 commit intotreeowl:masterfrom
Conversation
|
I'm sorry for not getting to this for so long. I've left several comments. |
|
|
||
| {-# INLINE indexed #-} | ||
| indexed :: forall f a s. (Ord a, Foldable f) => f a -> ST s (VM.STVector s a) | ||
| indexed x = do |
There was a problem hiding this comment.
I don't think this implementation is the right approach. A left fold is too weird here, and you're building up a big closure chain. Why not just use the conversion Data.Vector offers? Alternatively, you could get really fancy and do a little local sorting along the way, but that would mean digging into the sorting algorithm to avoid duplicating work. On the plus side, that would really do a good job of justifying the addition of this module to what's otherwise a proof of concept package.
| import qualified Data.Vector.Algorithms.Intro as Intro | ||
| import qualified Data.Vector.Mutable as VM | ||
|
|
||
| {-# INLINE sortTraversableBy #-} |
There was a problem hiding this comment.
This name is confusing. This is not actually a sorting function at all, and the Ord constraint isn't needed.
Seems to be much faster across the board.
I originally used a simpler implementation which just used
Foldable'slengthto get the length of the target vector, which was only faster for very large (100,000+) lists and Seq.Benchmark results: