Map/Set.prototype.size is O(n)

Michał Wadas michalwadas at gmail.com
Wed Mar 29 15:29:18 UTC 2017


Implementations aren't required to follow exactly these steps, just to
have the same result.


On 29/03/17 17:15, Daniel Herman wrote:
> In reading the relevant section for the `size` accessors
> (http://www.ecma-international.org/ecma-262/7.0/index.html#sec-get-map.prototype.size
> <http://www.ecma-international.org/ecma-262/7.0/index.html#sec-get-map.prototype.size>),
> I'm confused and wondering why this was defined as an O(n) operation
> in the `get` accessor rather than as an additional step in the `set`,
> `delete`, and `clear` methods to track an internal `[[Size]]` variable
> or something, making the public `size` accessor capable of being O(1).
>
> It seems surprising to me that in order to be spec compliant, Map and
> Set implementations must implement accessors that have surprising perf
> implications.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170329/9ce48425/attachment.html>


More information about the es-discuss mailing list