2 ms·
> you can O(1) insert into the middle of Array-likes like Set in JS Sets are supposed to retain the insertion order. I don't think you can insert into the midd
by selcuka 3y ago
> you can O(1) insert into the middle of Array-likes like Set in JS
Sets are supposed to retain the insertion order. I don't think you can insert into the middle, let alone in O(1) time (as they are hashmaps, not linked lists).
> I hate language vs language debates!
I wasn't trying to compare JS to Python. My aim was to clarify a misunderstanding re: data structures used.
- _akhe 3y agoIn the case of `Set` and `Map` they're keys though. It's sorted in that you can reference `data[1]` and get that element, but I don't know the keys are necessarily sorted. This guy says "V8 team explains how some memory optimization was done on its hashtable implementation for Map, Set, WeakSet, and WeakMap: Optimizing hash tables: hiding the hash code Based on 1 and 2: V8's Set and Map's get & set & add & has time complexity practically is O(1)." https://stackoverflow.com/questions/33611509/es6-map-and-set-complexity-v8-implementation https://stackoverflow.com/questions/33611509/es6-map-and-set...