This repository has been archived by the owner on Jul 23, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new data type to immutable-js named SortedList, a Collection.Set subtype. Addresses #181. My description in the docs:
This patch is usable in practice, but is not ready to be merged. add(), first(), last(), shift(), pop() and ES6 iterate all work but other functions either are absent or retain the List.js implementation and will error.
SortedList works using a tree of list-of-lists, like List.js, but because insertion is at arbitrary location by design, instead of all nodes being kept full the list-max is treated as a maximum and if a node tries to exceed the maximum it splits into two halves. Because the node list length is variable, each node tracks the minimum and maximum value in its branch of the tree to make navigation possible. Pointers are maintained to the least and greatest leaf nodes for constant first/last value access.
For my own amusement, and because I have had trouble getting the immutable-js automated tests to run, I wrote a standalone Preact app for testing and debugging SortedList:
To use this, check out both the sortedlist-pr branch and the test app, run
npm run build
in the sortedlist-pr dir, and runnpm link ../path/to/sortedlist
in the test app dir.To test SortedList before submitting this PR, I temporarily reduced the node list max size to 4 and used this app to run 40,000 random operations on a list while verifying invariants (list is in sorted order; node min and max memos are accurate; head and tail point to actual head and tail) at each step. (This test was on immutable.js mainline; I also tested 20,000 operations on the -oss branch with the standard node list size of 32. See note at end.)
Here are the issues that I think need to be resolved before accepting this PR:
Here are some things I think would be “nice to have” when including this in a release:
Here are the things I think I need help with:
__hash
?@@transducer
? How do I implement it? (Conrad is helping me with this in Slack.)__iterator
and__iterate
? What protocol do implementations of these two functions follow? (I think I understand__iterator
but not whether “type 2” is mandatory, and I don’t understand what__iterate
does.)Finally, I have one problems which is unique to the -oss repo, and which I don't know how to fix:
I got this error when running
yarn build
:I don't get this building mainline immutable-js with npm. I don't get this building your normal master with yarn. Despite the error, I was still able to run my test app by, after running
yarn build
, deletingnode_modules
and then runningnpm link
in the test app directory.I think this error might be because I typed a parameter in a function overload in the d.ts in my patch as the literal "null". If your tool thinks that's an error, your tool is bugged. That's legal TypeScript.
I have also submitted a version of this to immutable-js. My working branch with non-squashed commits is here.