Skip to content
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

Linked List insertion, remove and reordering #170

Open
jramstedt opened this issue Sep 10, 2021 · 3 comments
Open

Linked List insertion, remove and reordering #170

jramstedt opened this issue Sep 10, 2021 · 3 comments

Comments

@jramstedt
Copy link

There is no way to insert new values between values, remove values or move (reorder) values in the list.

Currently there is no benefit of using linked list instead of array.

@Yomguithereal
Copy link
Owner

Hello @jramstedt, this is true indeed but I must admit I did not implement this out of laziness since I never had a legitimate use case for linked list in javascript that was not counterproductive, performance-wise. This is not to say that you don't have a legitimate use-case, it's just I don't implement things that are not used. Would this be useful to you? Can you explain your use case to me? I have a prototype of a way to implement a very efficient linked-list in JavaScript if you can guarantee that you know the maximum number of elements you will need for instance, but I never industrialized it for lack of a reason to do so.

@jramstedt
Copy link
Author

Uses for single linked list are few. Double linked list is more useful in general and would like to see that implemented here too.

I use BiMaps from this library already and had need for linked list. I did find another package, that I'm currently using, but that isn't perfect for my use either.
I'm using double linked list for sprite draw ordering. I use it to add, remove and update sprites without having to do depth sorting when they move. All I need to do is travers forward or backward the list and update links when correct place is found.

@Yomguithereal
Copy link
Owner

Yomguithereal commented Sep 17, 2021

Hello @jramstedt,

I know the typical use cases for linked lists. My point is that, often, linked lists in JavaScript are not worth it performance-wise, even against inferior O(n) algorithms relying on flat arrays. So I have some questions: 1. how many items are we speaking of? 2. have you tried benchmarking suboptimal linear algorithms against the linked list solution you are using and 3. in your use case, do you always know the upper bound for the max number of items your list may need to store?

Then, if you want we can discuss the addition of an especially performant implementation of a doubly-linked list that could suit your use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants