4 ms·
Only the usual reasons to use a linked list. E.g. if you want to store stable references to cells in the linked list as in a linked hash map.
by wffurr 5y ago
Only the usual reasons to use a linked list. E.g. if you want to store stable references to cells in the linked list as in a linked hash map.
- oweiler 5y agoThat would be JavaScripts native Map, no?
- wffurr 5y agoTIL ES6 Map is guaranteed to iterate in insertion order. That always made me crazy in C++ too; the structure that I usually actually want is std::unordered_map not std::map. There are other algorithms and use cases for a stable iteration into an ordered sequence, but I can’t think of any off-hand. It is true that it’s rare to prefer a linked list on modern CPU architecture.
- filoeleven 5y agoAre there practical reasons for using a linked list in JS? This is an honest question. I’ve taken immutability to heart, so storing a stable yet presumably mutable reference to a cell seems like a bad idea to me. (If it’s immutable, you can keep and use the cell’s value instead of caring that it came from a list.)