-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Document time complexity #3
Comments
@joebandenburg this is how you would naturally implement it (without overthinking optimisation in first place). It's also how ECMAScript specifies the lookup, (it's Still, of course lookup can be internally more optimal, and there's already opened issue for that. See #2 |
@medikoo : @joebandenburg is correct. See my question on point, including (for example, from the ES6 spec):
So using O(n) array lookup differs from the requirements of the spec, and so probably worth noting (IMHO). Cheers |
@brianmhunt yes, but it's not possible to obey to that paragraph without altering the objects which are added as map keys, and for frozen objects it's not possible at all. So if you look at it from right perspective, every Map polyfill should contain similar note :) Anyway since v1 es6-map will do O(1) for most (not frozen of course) cases, I agree it's acceptable in ES5 world (it defnitely wouldn't in ES3 world, but this polyfil doesn't support ES3) |
I noticed many people trying to use this library expected O(1), therefore I added note as requested to the readme. |
From my reading of the code, you're using arrays to store the keys and values and searching them linearly in
get
andset
. I think you should document in your README that the polyfill has worst algorithmic complexity than a real Map implementation. The polyfill insert and lookup operations areO(n)
whereas any decent native implementation will haveO(1)
(or perhapsO(log n)
) operations. This difference may matter to your users.The text was updated successfully, but these errors were encountered: