-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature request: Priority queue / self-sorting list [can PR] #14
Comments
From mcclure on Sat, 10 Oct 2020 15:31:06 GMT ownerID in List is only needed for the implementation of mutable mode, right? Copied from original issue: #14 |
From mcclure on Mon, 12 Oct 2020 22:52:49 GMT Made a StackOverflow question about my difficulties running Copied from original issue: #14 |
From mcclure on Fri, 09 Oct 2020 15:54:00 GMT Got some help on Twitter, here's the best I can understand: List is an "Vector Trie" apparently patterned on the Scala vector type, meaning it's a tree where every leaf is an array of maximum 32 elements. Bottom leaves other than the rightmost are assumed to be filled and when you lookup an index the node you're looking for is found by pure math, which is why midlist insert is O(N). My plan is:
On top of this basic plan, I may attempt the following two nice-to-haves:
I haven't done any proofs this is actually efficient, but my intuition is that because removal is generally only done at the beginning and end and insertion cannot reduce leaf size below 16, that this will give between O(log_16(n)) and O(log_32(n)) performance on insertions, front pops and end pops, and this is provable. This approach would resolve the problem in my application. If I get it working, would you be interested in merging it? What requirements do you have that a new feature like this has adequate perf (ie, do you require proofs, or just verification of good average-case performance in testing?) Things I'm not clear on yet:
I can't even figure out what script is trying to invoke Copied from original issue: #14 |
From mcclure on Tue, 13 Oct 2020 05:34:26 GMT I've started on an implementation of this, feature branch is here https://github.com/mcclure/immutable-js/tree/pq This adds an exported SortedList and isSortedList. SortedList has a complete implementation of one function, add(). If you call it, it crashes. (The implementation of "add" turned out to be more complicated than I thought! I don't actually know whether my approach is actually more efficient than just using a balanced tree or something.) Will make an initial PR once I have add, pop and shift working. Copied from original issue: #14 |
From mcclure on Sat, 10 Oct 2020 16:30:31 GMT Also, what are the "@@transducer/" functions for? I do not find any description of them in the docs. Copied from original issue: #14 |
From mcclure on Fri, 09 Oct 2020 15:56:29 GMT (One other small thing: an alternative to using the "key function" would be make this a key/value store and sort on the key. This would result in the same implementation but a slightly different external interface. I think this approach is a little weird because you can have multiple values sharing a single key, but I don't have a strong opinion either way about it.) Copied from original issue: #14 |
From mcclure on Thu, 08 Oct 2020 05:15:11 GMT
Hi, I have a need for a "priority queue" style data structure, or more specifically I need an immutable structure that I can add items to in arbitrary order and then repeatedly efficiently iterate over according to some fixed property (for example if I have a list of objects
obj
, I might want to keep it sorted by the keyobj.date
).I need this enough I plan to attempt an implementation myself. I would be happy to write a PR if there is a specific way I could write it that you would be willing to accept.
I find a number of algorithms online for immutable priority queues, but it seems like it might be a good idea to base my implementation on the existing list structure rather than implementing a totally new structure. For this reason I am curious if there is any "contributor documentation" that would help me understand the underlying principles of immutable.js List. I am pawing through the source but not having much luck understanding where the important parts are. List.js seems to be describing something like a linked list but each node has this "array" member rather than a next reference and I'm not sure what "array" contains.
Copied from original issue: immutable-js#1791
The text was updated successfully, but these errors were encountered: