-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Feature request: Priority queue / self-sorting list [can PR] #1791
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
Comments
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 |
(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.) |
ownerID in List is only needed for the implementation of mutable mode, right? |
Also, what are the "@@transducer/" functions for? I do not find any description of them in the docs. |
Made a StackOverflow question about my difficulties running |
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. |
@mcclure can you re-open [your PR][https://github.com/immutable-js-oss/pull/183) here as you said that it is not ready to be merged in the old fork ? |
I have a version of the PR here also, actually, it is this: There are some questions (i think some of the Set methods don't work), it would be good for someone with more familiarity to look at which standard interface bits are not present. I think I failed to implement the cursor method? |
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.
The text was updated successfully, but these errors were encountered: