JS team should include heap data structure as built in data structure. It will be very helpful for developers
Including a heap data structure would greatly benefit developers. This would reduce the dependency on external libraries for solving DSA (Data Structures and Algorithms) problems, giving developers more complete control over JavaScript. Furthermore, when preparing for DSA interviews, JavaScript developers would not need to learn the syntax of other languages. This is a significant advantage as we build end-to-end applications and would be a valuable contribution to the developer community, especially for those who are new
Thanks for your post. It reminds me about discussions within the Committee about standardizing more basic data structures. I’ve seen some appetite within the Committee for standardizing a few more basic data structures.
- The biggest interest I’ve seen from at least one engine implementer is for queues and stacks. This is because JavaScript’s built-in arrays are expected to function simultaneously as lists, queues, and stacks. This has necessitated engines’ arrays to implement arrays with cursed and complex algorithms that need to cover all those use cases performantly.
- There’s also been some interest in the Committee about standardizing multimaps.
- I’ve also seen arguments over whether these standard data structures would make JavaScript “too Java-like”.
I do not have a strong opinion about this, but many other Committee people will likely argue that the opposite is the case: by using an engine’s implementation of a data structure, you give up control to the engine’s implementation. You no longer are able to modify the implementation in JavaScript userspace yourself. There are many ways to implement a heap. By implementing your own heap or importing a library, you get to choose what kind of heap you want.
In general, the Committee gives a higher priority to features that are currently difficult or impossible to implement in JavaScript userspace. We’ve been able to add some developer-convenience features that are polyfillable by userland code, but it’s a more uphill battle, because we need to persuade the engines that the feature-that-developers-can-already-do-on-their-own is worth the perpetual new burden on the engines.
Anyways, the Committee probably would focus on things like queues, stacks, or multimaps before heaps. There are many ways to implement a heap, and heaps are probably less commonly used across programs. It’s an interesting idea though. Thanks for the post.
Reminds me of when I once saw SpiderMonkey using a resizable circular buffer for it. That implementation was especially cursed.