-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Make list.unique
logarithmic instead of quadratic
#678
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you 💜
But unfortunately there's an import cycle.
|
Looks like you have a compile error! |
So I have to come up with a different solution |
236a899
to
bd0da5a
Compare
@@ -1151,7 +1152,7 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) { | |||
|
|||
/// Removes any duplicate elements from a given list. | |||
/// | |||
/// This function returns in loglinear time. | |||
/// This function returns in logarithmic time. |
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.
This is wrong, the algorithm is loglinear O(n logn)
since it still has to iterate over the whole list
This looks good to me! I've left a small note inline. Also could you update the changelog? |
Fixes #667.
NewNewlist.unique
implementation usesgleam/set
to detect whether item has already been seen.list.unique
implementation usesgleam/dict
to detect whether item has already been seen (it can't usegleam/set
because that would create import cycle).