-
Notifications
You must be signed in to change notification settings - Fork 8
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
Set.prototype.at #51
Comments
Sets are not an integer-indexed data structure. While they have a deterministic iteration order, they are representing unordered collections (in the sense that you cannot access them by position, or reorder/sort them). |
The fact that they are iterated in insertion order is enough for my desire. |
Then iterate your set. An
or the iterator helpers
to log the third element. This should not be easy, the syntax should make it clear that the set is iterated. |
Eh, it's a little more complicated than that - the underlying data structure in fact gives you constant time random access unless you've deleted elements, though once you start deleting things it becomes much more complicated. But since it's not always constant time, |
The devtools display in a given browser is not indicative of much of anything. Devtools are optimizing for displaying things to users, not reflecting underlying reality. If you look at the actual implementation used in Chrome and Firefox it does not support constant time indexing after deleting things. Safari uses a different implementation (a hashmap plus a linked list) but it doesn't support constant time indexing either. |
@oleedd it's still a custom thing even if every browser chooses to display it the same. |
Then this custom thing may be used. |
The custom thing involves reading through the entire set, or at least some subset of it, for display. Which is fine for rendering it but not fine for random-access indexing. If you don't want to take my word for it you can inspect the data structures yourself; these engines are all open-source, and I've already linked a good summary of the structure used in Chrome and FF. You are not going to convince anyone that this is possible by any means other than demonstrating that the data structures used to implement these in engines somehow do actually support random-access indexing, and pointing to the rendering in the devtools does not demonstrate this. As to the similarity between Chrome and FF, devtools often copy each other, or converge to similar endpoints, because users appreciate the familiarity. It is not a coincidence that they have similar renderings, but neither is it standardized. |
To remember insertion orders, they have to use indexes inside actually. |
That is not true. In some implementations there are indexes involved, but after items have been deleted these indexes do not correspond to the indexes you'd get from iterating in userland, so they're not useful here. Simply asserting otherwise does not make it so. They are open source; you can see for yourself. I don't think it's really useful for me to keep repeating myself, so I'm going to stop responding now. |
Those internal indexes may be these "Entries", which change after deleting as well. Saving those empty slots and skipping them for creating entries for iteration is not very smart. |
I just gave a potential way to help. I didn't intent to give irrefutable proof. |
If some engines remain empty slots, they can rebuid internal indexes after deleting, how it is going with |
Even if |
There are many iterable data structures that aren't indexable, the most obvious and simplest being a linked-list, in which each item knows where the next item is, but the data structure itself only knows where the first item is. You can only access the nth item by iterating over n-1 previous items in order to find it. While You can of course already do this in O(n) by iterating through the Set until the nth element with a simple As for devtools, I suspect it's basically just doing |
The text was updated successfully, but these errors were encountered: