-
Notifications
You must be signed in to change notification settings - Fork 69
use Ord for nub #128
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
use Ord for nub #128
Conversation
Actually this should always be O(n*logn), as the array sort should provide the upper bound. |
Thought of a simpler technique, will update this. |
7f9dcbf
to
2b85642
Compare
ready for review |
This is great, but I would like to preserve the property that |
Also if we don’t have a test for that property, I’d quite like to add one. Doesn’t have to be via quickcheck; if dependencies make quickcheck difficult that’s fine, we can just test it on some hardcoded set of cases. |
Could you reference the original issue in the commit as well please? |
Very much agreed w/preserving the original order! |
Will use this if merged: #130 |
addresses purescript#91 O(n*logn)
I've incorporated the suggestions above. This is ready for review. |
Actually, I'll add |
Okay, ready for review :). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised, if nub has an Ord constraint, then nubBy should really take an a -> a -> Ordering, so that nub = nubBy compare. We could rename the current nubBy to nubEqBy.
The old `nubBy` becomes `nubByEq`, which only requires an equality relation.
Done. |
Looks great! Do you know what the big-O for this new implementation should be? Since this is breaking I think it makes sense to merge this as part of the 0.12 updates. |
Your upper bound should be set by Hopefully my thinking here is correct. Should I add a comment to this effect? |
I should add that if for some reason your FFI'd |
Sounds good. I think we can assume that |
I merged this by hand into the compiler/0.12 branch. Thanks! |
On JS engines where
Array.push
is amortized O(1) (I believe this to be common), this should be amortized O(n*logn).