Traversal in insertion order for Set.prototype.add/delete

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Traversal in insertion order for Set.prototype.add/delete

Qantas 94 Heavy
Maybe my brain's just fried, but is there any reason for Set.prototype.add and Set.prototype.delete enforcing iteration "by original insertion order"? There aren't any side effects that I know of by iterating through the list of elements in some other order, as all the elements of a set are meant to be unique. Am I missing something?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Traversal in insertion order for Set.prototype.add/delete

Mark S. Miller-2
We need a deterministic order. What deterministic order do you suggest? Why would it be better?


On Wed, Apr 23, 2014 at 7:36 PM, Qantas 94 Heavy <[hidden email]> wrote:
Maybe my brain's just fried, but is there any reason for Set.prototype.add and Set.prototype.delete enforcing iteration "by original insertion order"? There aren't any side effects that I know of by iterating through the list of elements in some other order, as all the elements of a set are meant to be unique. Am I missing something?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
    Cheers,
    --MarkM

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Traversal in insertion order for Set.prototype.add/delete

Qantas 94 Heavy
We need a deterministic order. What deterministic order do you suggest? Why would it be better?

Sorry for the confusion, I completely worded that wrong.

I'm specifically referring to the specification sections 23.2.3.1 and 23.2.3.4 (specifying the behaviour for Set#add and Set#delete), which states that:

6. Repeat for each e that is an element of entries, in original insertion order

I don't see any real reason why that's needed, unless there's some odd side effects of doing so that I'm not aware of. Sets are meant to be unique and I don't think the order of checking whether the element already exists really matters. I'm not advocating for any change for the deterministic order of iteration in Set#forEach and for-of loops on sets.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Traversal in insertion order for Set.prototype.add/delete

Mark S. Miller-2
I don't understand the issue. Could you give a tiny example test case for checking the specced order vs one for checking the order as you think it should be specced?


On Wed, Apr 23, 2014 at 8:54 PM, Qantas 94 Heavy <[hidden email]> wrote:
We need a deterministic order. What deterministic order do you suggest? Why would it be better?

Sorry for the confusion, I completely worded that wrong.

I'm specifically referring to the specification sections 23.2.3.1 and 23.2.3.4 (specifying the behaviour for Set#add and Set#delete), which states that:

6. Repeat for each e that is an element of entries, in original insertion order

I don't see any real reason why that's needed, unless there's some odd side effects of doing so that I'm not aware of. Sets are meant to be unique and I don't think the order of checking whether the element already exists really matters. I'm not advocating for any change for the deterministic order of iteration in Set#forEach and for-of loops on sets.



--
    Cheers,
    --MarkM

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Traversal in insertion order for Set.prototype.add/delete

Allen Wirfs-Brock
In reply to this post by Qantas 94 Heavy

On Apr 23, 2014, at 8:54 PM, Qantas 94 Heavy wrote:

We need a deterministic order. What deterministic order do you suggest? Why would it be better?

Sorry for the confusion, I completely worded that wrong.

I'm specifically referring to the specification sections 23.2.3.1 and 23.2.3.4 (specifying the behaviour for Set#add and Set#delete), which states that:

6. Repeat for each e that is an element of entries, in original insertion order

I don't see any real reason why that's needed, unless there's some odd side effects of doing so that I'm not aware of. Sets are meant to be unique and I don't think the order of checking whether the element already exists really matters. I'm not advocating for any change for the deterministic order of iteration in Set#forEach and for-of loops on sets.

You're right that phrase isn't need for probing operations such as used by add and delete.  It only matters for iteration operations.  In fact, that phrase doesn't appear in the corresponding methods of Map. I'll remove the unnecessary requirement.

Allen


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss