Skip to content
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

Replace quadratic-time algorithm for uniques()? #46

Closed
jtrim-ons opened this issue Jun 11, 2021 · 4 comments
Closed

Replace quadratic-time algorithm for uniques()? #46

jtrim-ons opened this issue Jun 11, 2021 · 4 comments

Comments

@jtrim-ons
Copy link
Contributor

The uniques() function checks if each item is in an array of seen items, which I think leads to quadratic complexity overall. There are probably use cases such as a scatter plot with thousands of points where this would take a noticeable length of time.

Would it be worth making seen a Set? I think it would just need the following changes:

  • const seen = []; -> const seen = new Set();
  • seen.includes(computed) -> seen.has(computed)
  • seen.push(computed) -> seen.add(computed)
@mhkeller
Copy link
Owner

Ah very good idea! This function was a holdover from another era.

@jtrim-ons
Copy link
Contributor Author

Great - I'll have a go at a PR just now.

@mhkeller
Copy link
Owner

Thanks for jumping in! I'll take a look!

@mhkeller
Copy link
Owner

Sorry for the delay! This is now published as v4.1.1! Thanks again! I'll hopefully get some time in the coming two weeks to go over the calcExtents API change, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants