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

Faster implementation #16

Open
lovasoa opened this issue Sep 2, 2019 · 1 comment
Open

Faster implementation #16

lovasoa opened this issue Sep 2, 2019 · 1 comment

Comments

@lovasoa
Copy link

lovasoa commented Sep 2, 2019

In case you are interested, I just published a faster implementation of the same algorithm: lovasoa/fast_array_intersect.

Here are the things you could improve in your version :

  • Fill the initial map using the smallest of the arrays, not the first
  • iterate over arrays using for(var i=0; i<a.length; i++) instead of for(var i in a)
  • implement a premature stopping condition as soon as the intersection is empty
  • (only in ES6) use a Map instead of an object
@juliangruber
Copy link
Owner

Awesome! Thanks for sharing your insights :) I'm going to keep this issue open for anyone to learn, discover your version of pick up working on it 🙏

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